Getting Read Only Filesystem Error inside a docker container - docker

This command
echo 1 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6
when run inside a CentOS docker container (running on Mac), gives:
echo 1 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6
tee: /proc/sys/net/ipv6/conf/all/disable_ipv6: Read-only file system
1
When run inside a CentOS virtual machine, it succeeds and gives no error.
The directory permissions inside docker container and VM are exactly the same:
VM:
$ ls -ld /proc/sys/net/ipv6/conf/all/disable_ipv6
-rw-r--r-- 1 root root 0 Jan 4 21:09 /proc/sys/net/ipv6/conf/all/disable_ipv6
docker:
$ ls -ld /proc/sys/net/ipv6/conf/all/disable_ipv6
-rw-r--r-- 1 root root 0 Jan 5 05:05 /proc/sys/net/ipv6/conf/all/disable_ipv6
This is a fresh, brand new container.
Docker version:
$ docker --version
Docker version 18.09.0, build 4d60db4
What am I missing?

Try hackish solution and add extended privileges to the container with --privileged:
$ docker run --rm -ti centos \
bash -c "echo 1 | tee /proc/sys/net/ipv6/conf/all/disable_ipv6"
tee: /proc/sys/net/ipv6/conf/all/disable_ipv6: Read-only file system
1
vs
$ docker run --privileged --rm -ti centos \
bash -c "echo 1 | tee /proc/sys/net/ipv6/conf/all/disable_ipv6"
1
You can use --cap-add to add precise privilege instead of --privileged.
However --sysctl looks like the best solution, instead of hacking networking in the container with --privileged:
$ docker run --sysctl net.ipv6.conf.all.disable_ipv6=1 \
--rm -ti centos bash -c "cat /proc/sys/net/ipv6/conf/all/disable_ipv6"
1

Related

Can't change ownership of '/dev/gpiomem' in a docker container in RPi

I'm trying to run a simple docker container with a python base image to control the LEDs on my RPi4.
The Dockerfile compiles fine and I'm running it as follows:
docker run --rm -ti --privileged --device /dev/gpiomem:/dev/gpiomem -d led_blinker bash
Once inside the docker container I run a ls -l /dev/gpiomem and I get
root#ca1506d00cc5:/# ls -l /dev/gpiomem
crw-rw---- 1 nobody nogroup 246, 0 Dec 30 21:47 /dev/gpiomem
I try to do
root#ca1506d00cc5:/# chown root.root /dev/gpiomem
chown: changing ownership of 'dev/gpiomem': Operation not permitted
But when I run a whoami I get I'm the root user. What is that I'm missing?
PS. I have also added the flag --user root and got the same results.

Docker: Mounted directory doesn't have files

I'm trying to mount a directory along with all of it's file contents. But it seems to only mount the directory without the contents:
> ls ~/test_dir
testfile
> docker run -it --rm --entrypoint bash -v ~/test_dir/:/test_dir:ro my_image:latest
bash-4.2# cd test_dir
bash-4.2# ls -a
. ..
bash-4.2#
I'm using Oracle Linux 7.9 terminal
Docker version 20.10.9

pending when starting a container on remote host

I have already configured remote api for docker in my server.
$ ps -ef |grep dockerd
root 5191 1 0 5월08 ? 00:01:41 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:4243
When I run a container in a Jenkins container running in my server,
The container is pended after creating the container.
[Execute Shell]
export DOCKER_HOST=tcp://10.254.239.53:4243
docker run -it --rm ubuntu:18.04 ls
<--- pending and display nothing
The result of docker ps -a in my server
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
609198e3928d ubuntu:18.04 "ls" 8 seconds ago Created lucid_curran
When I execute the same command with "-d" option, it is ok. But useless.
[Execute Shell]
export DOCKER_HOST=tcp://10.254.239.53:4243
docker run -d ubuntu:18.04 ls
When I run the same command in my server, executed correctly.
$ docker run --rm -it ubuntu:18.04 ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
How do I fix this error?

Docker in Windows is mounting files as directories

I'm trying to run this command in my Powershell:
docker run -u postgres --net host -v /`pwd`/file.sql://tmp/setup.sql --rm postgres:9.4 psql -h localhost -U postgres -f //tmp/setup.sql my_db;
which is giving me this error:
psql:/tmp/setup.sql:0: could not read from input file: Is a directory
I tried running a bash in that docker container via this command:
docker run -it -u postgres --net host -v /`pwd`/file.sql://tmp/setup.sql --rm postgres:9.4 bash
and then did a simple ls -l /tmp inside the docker tty, and it's showing that setup.sql file is actually a directory!
drwxr-xr-x 2 root root 40 Jan 13 08:39 setup.sql
How do I go about doing this? I've also tried the bash shell supplied by msysgit with the same results.

Cannot mount data volume in Docker with Windows

I am running Docker on Windows. I have succesfully build an image with command:
docker build -t my/tag /c/Users/user/Docker/docker-php/image/
docker images result:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
my/tag latest 763a2f01c832 28 minutes ago 445.8 MB
php 5.6-cli 32d2bd1d7a19 6 days ago 444.5 MB
Unfortunately I have a problem, when I am trying to mount data volume to image. I run:
docker run --rm -it -v /``pwd``:/src -w /src my/tag bash
(There is single backtick on pwd, but I don't knwo how to escape it.)
But files aren't visible in docker:
root#3e91981ef517:/src# ls -al
total 4
drwxr-xr-x 2 root root 40 Aug 31 18:59 .
drwxr-xr-x 47 root root 4096 Aug 31 19:15 ..
I have tried with different approach, such as:
docker run --rm -it -v /``pwd``:/src -w /src my/tag bash
(There is single backtick on pwd, but I don't knwo how to escape it.)
docker run --rm -it -v /full/path/to/sources:/src -w /src my/tag bash
docker run --rm -it -v //full/path/to/sources:/src -w /src my/tag bash
But every time the same result.

Resources