How to fix docker error "readonly file system: unknown"? - docker

I was treing to set the project on my local machine as readonly for the docker container, like this:
docker run -d \
-p 3000:3000 \
-v $PWD:/app:ro \
-v /app/node_modules \
--name $1 \
$(docker images | awk '{print $1}' | awk 'NR==2')
and I always get this error, only after I add the :ro bit as the optional parameter to the volume:
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/var/lib/docker/volumes/6ffd471c1bc7edc141b6569b4d8e16829c7c7ae1838e4cc924727b0a854de143/_data" to rootfs at "/app/node_modules" caused: mkdir /var/lib/docker/overlay2/60b790308084302171b1b339ee242862651d7d96ecf21fb9b0a8867326ca83b3/merged/app/node_modules: read-only file system: unknown.
I was following this tutorial and I am using docker-desktop and WSL2 on windows 11.

Actually the :ro is causing issue here on building the container on first time you must have the node_modules folder locally after that you can delete it

In my case, i've solved this creating a container with --privileged parameter.
to do:
docker run --privileged -i --name master --hostname k8s-master -d ubuntu:20.04
now, its fine.

Related

Is it possible to access mptcp sysctl inside docker?

I would like to access sysctl -n net.mptcp.mptcp_enabled from docker container, but currently I couldn't achieve it. I already tried the below things.
1.
docker run -d --sysctl net.mptcp.mptcp_enabled=1 --name=test -p 3100:3100 my_container
75dcbdc65a1539ce734a413cb6e23bf216aea76f6533c52280d3e866270424b9
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: write sysctl key net.mptcp.mptcp_enabled: open /proc/sys/net/mptcp/mptcp_enabled: no such file or directory: unknown.
docker run -d --cap-add=SYS_ADMIN --privileged --name=test -p 3100:3100 my_container
This time container starts but there is no file under /proc/sys/net/mptcp/mptcp_enabled
3.
docker run -d -v /proc:/proc --cap-add=SYS_ADMIN --privileged --name=test -p 3100:3100 my_container
This is also the same as 2.
I saw that a sysctl that starts with net.* are namespaced but wonder why this is not working.
Note: My host machine has mptcp supported kernel and I can see all mptcp related files under /proc/sys/net/mptcp/*
I faced the same issue. Using --net=host should solve it.
Try this:
docker run -d --net=host --name=test -p 3100:3100 my_container

Pass configuration file to mosquitto in Docker container

Trying to run masquitto Docker container on Windows. I have directory structure:
..
mosquitto
config
-- mosquitto.conf
data
log
I run command:
docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto
Got error:
docker: Error response from daemon: source /var/lib/docker/overlay2/c54f317f73085489398e1b2c4ffbc85fbdb18073e8a0fa60f11a7f7222fbc49d/merged/mosquitto/config/mosquitto.conf is not directory.
See 'docker run --help'.
What I do wrong?
UPD
I tried to provide full path to config file on host machine:
docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto
Got error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:59: mounting "/run/desktop/mnt/host/c/docker_tst/eclipse-mosquitto/mosquitto.conf" to rootfs at "/var/lib/docker/overlay2/d9a7cbcb0f85b195dc5ee2d0999b3df8c84324552f6c45cf218876e9b96ed826/merged/mosquitto/config/mosquitto.conf" caused: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
PS C:\docker_tst\eclipse-mosquitto>
From the comments, the solution was to provide an absolute path to the single mounted file, per this answer.
On Unix based systems or in Windows Subsystem for Linux, you can do this by running something like:
docker run -v $PWD/filename:/path/in/container IMAGE_NAME
However, the process is different on Windows, per this answer.
In PowerShell, you can run Get-Location or pwd to get the current directory where your file is and switch the \ to / (forward slashes). For this example, the solution was to use this command:
docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquito/config/mosquito.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto

How can I add an extra bind-mount to this configuration?

There are two ways of passing arguments, I chose this one:
sudo docker run -d -e url=http://example.com --name myBlog -p 3001:2368 -v "$(pwd)/content":/var/lib/ghost/content ghost:latest
How can I add an extra command line so it also adds a bind-mount to:
$(pwd)/testFolder/config.production.json the file on the volume would be here: :/var/lib/ghost/config.production.json
Also the file on the host doesn't exist yet, once I mount the container, it the container creates it.
This is what I've tried:
sudo docker run -d -e url=http://example.com --name myBlog6 -p 3006:2376 -v "$(pwd)/content6":/var/lib/ghost/content -v /home/ubuntu/config6:/var/lib/ghost/config.production.json ghost:latest
But I'm getting this error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/home/ubuntu/config6\\\" to rootfs \\\"/var/lib/docker/overlay2/f8c4ed9231552e91caaeb4f0b8fb9f02108f838e94b659bf049a2df365cd26ef/merged\\\" at \\\"/var/lib/docker/overlay2/f8c4ed9231552e91caaeb4f0b8fb9f02108f838e94b659bf049a2df365cd26ef/merged/var/lib/ghost/config.production.json\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
Thanks
If I got it correctly, you get this error because you are trying to mount directory /home/ubuntu/config6 to a file ...config.production.json.
If you say that file config.production.json will be created and it's content is written in run time after the container is initialized, then you could try to created an empty file
touch /home/ubuntu/config6/config.production.json
sudo chmod 777 /home/ubuntu/config6/config.production.json
and then mount a file to the container
sudo docker run -d \
-e url=http://example.com \
--name myBlog6 -p 3006:2376 \
-v "$(pwd)/content6":/var/lib/ghost/content \
-v /home/ubuntu/config6/config.production.json:/var/lib/ghost/config.production.json \
ghost:latest
And after container will write a content to file, you will be able to see it and load next time to the container.
The chmod command is used to make sure, that you app running inside of the container will have rights to write to this file.

how to customise docker and ipfs with a config file

I get this error:
sudo docker run -d --name ipfs-node \
-v /tmp/ipfs-docker-staging:/export -v /tmp/ipfs-docker-data:/data/ipfs \
-v /home/ubuntu/.ipfs/config:/data/ipfs/config \
-p 8080:8080 -p 4001:4001 -p 127.0.0.1:5001:5001 \
jbenet/go-ipfs:latest
ee613bda861afb7af65a2e9ba414f4421f76e232fcc4e10aee835038143372ca docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\"/home/ubuntu/.ipfs/config\\" to rootfs \\"/var/snap/docker/common/var-lib-docker/aufs/mnt/79b6c9331582b87d40683c784347974cf77a978cddb4e6cc04804bf856563236\\" at \\"/var/snap/docker/common/var-lib-docker/aufs/mnt/79b6c9331582b87d40683c784347974cf77a978cddb4e6cc04804bf856563236/data/ipfs/config\\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
Use --mount for standalone files:
sudo docker run -d --name ipfs-node \
-v /tmp/ipfs-docker-staging:/export -v /tmp/ipfs-docker-data:/data/ipfs \
--mount type=bind,source=/home/ubuntu/.ipfs/config,target=/data/ipfs/config \
--net=host \
ipfs/go-ipfs:release
Here is why: https://docs.docker.com/storage/bind-mounts/#differences-between--v-and---mount-behavior
PS. use official Docker images from ipfs/go-ipfs:release
PS2. use host interfaces via --net=host unless you really need NAT provided by Docker

dockerd[1455]: time="2017-12-18T19:08:30.299677811+03:00" level=error msg="stream copy error: reading from a closed fifo"

I'm calling host docker command line utility from inside of docker container on Ubunty via making it available inside container with volume by passing the host binaries, lib and unix socket when calling docker run as volumes like that:
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/bin/docker:/usr/bin/docker \
-v /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
Then inside container I'm calling:
docker run --rm - --hostname registrator_notificator_222444 -it -P -d \
-e CONSUL_1=172.17.0.3:8301 mycontainername:5043/app/myappname /etc
and then getting the error:
dockerd[1455]: time="2017-12-18T19:08:30.299677811+03:00" level=error msg="stream copy error: reading from a closed fifo"
What is fifo said in the error?
The problem was with wrong last parameter in the docker run call:
docker run --rm --hostname registrator_notificator_222444 -it -P -d -e CONSUL_1=172.17.0.3:8301 mycontainername:5043/app/myappname /etc
is was a typo and had no sence; it was leading for such error

Resources