how to customise docker and ipfs with a config file - docker

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

Related

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

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.

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.

Db2 with Docker: How to resolve error from bash script?

I have a syntax problem - Mac Mojave- starting a docker bash script:
docker run -h db2server \
--name db2server_fp4 \
--restart=always p 50000:50000 \
--env-file ${HOME}/db2devc.env_list \
${HOME}/db2devc:/database \
store/ibmcorp/db2_developer_c:11.1.4.4-x86_64
gives this error:
JMB:~ Juergen$ ./db2docker2.sh
Unable to find image 'p:latest' locally
docker: Error response from daemon: pull access denied for p, repository does not exist or may require 'docker login'.
See 'docker run --help'.
./db2docker2.sh: line 6: /Users/Juergen/db2devc:/database: No such file or directory
There seems to be a mistake in your docker run command. There is missing hyphen before the p and docker recognizes it as the image name.
There also seems to be a missing -v before what looks like a volume mount.
Try with the following command:
docker run -h db2server \
--name db2server_fp4 \
--restart=always -p 50000:50000 \
--env-file ${HOME}/db2devc.env_list \
-v ${HOME}/db2devc:/database \
store/ibmcorp/db2_developer_c:11.1.4.4-x86_64

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

Docker user permission while mounting a directory

I am using the following Dockerfile to build Solr using Docker.
FROM solr:5.5
ENV SOLR_HOME=/opt/solr/server/solr/cores
RUN mkdir ${SOLR_HOME}
RUN chown -R solr:solr ${SOLR_HOME}
VOLUME ["${SOLR_HOME}"]
EXPOSE 8983
I try to run the following Docker command to mount a host directory to the container:
docker run --restart=always -d --name solr-demo \
--privileged=true -p 8983:8983 \
-v /data/solr_demo:/opt/solr/server/solr/cores \
solr-test:latest
I am also copying the required solr.xml file into the data/solr_demo. When I run the docker run command I get the following error:
stat: cannot stat ‘/opt/solr/server/solr/cores’: No such file or directory 42146d74b446ba4784fd197688e3210f294aad8755ae730cc559132720bcc35a
Error response from daemon: Container 42146d74b446ba4784fd197688e3210f294aad8755ae730cc559132720bcc35a is restarting, wait until the container is running
From your comment, it appears you're mounting a nonexistent directory for your volume. Try this command that mounts /data/solr_demo1 instead of /data/solr_demo as your volume.
docker run --restart=always -d --name solr-demo \
--privileged=true -p 8983:8983 \
-v /data/solr_demo1:/opt/solr/server/solr/cores \
solr-test:latest
If it is really an user problem (it remind me of some issue I add with apache in container), you should consider using Gosu. https://github.com/tianon/gosu
It will let you run and swap user correctly and have a nice mapping from your local users and users inside the container.
Hope it will be useful.

Resources