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

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.

Related

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

Docker volume mount fails with the below error

Docker volume mount fails with the below error.
I'm trying to run a container with a config file in the volume and it fails with the below errors.
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data:/var/gerrit/etc/ forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data:/var/gerrit/etc forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc/ forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc/gerrit.config forkub
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 \\\"/root/data\\\" to rootfs \\\"/var/lib/docker/overlay2/0a5356aed5a1aa1d1359912ccba7547db55b0377b3a509b898828734868e335a/merged\\\" at \\\"/var/lib/docker/overlay2/0a5356aed5a1aa1d1359912ccba7547db55b0377b3a509b898828734868e335a/merged/var/gerrit/etc/gerrit.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.
ERRO[0000] error waiting for container: context canceled
Any suggestions on fixing this is really appreciated.
Thank you,
Anish
Probably the process in the container does not run as root but as some other user. The file belongs to root though and is not readable by the user that runs the process. So the process can not read the file.
So you need to make sure that the user that runs the process in the container can access those files. The easiest way would be to make /root/data world read-/writeable (chmod -R 777 /root/data) but this is obviously not the best way. The right way to do this, would be to find out which user is running the process in the container and change the ownership of /root/data and everything in it to that user.
The problem with docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc/gerrit.config forkub is, that you are trying to mount a directory /root/data to a file. This does not work.

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

docker nginx Mount -v

docker run command error: (I was knocking on the document command, Docker
version 18.03.0-ce), ask why?
docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
The error is as follows:
ebb97ea2c176cb1693912f54960db6281b30c95482c67df37183a8e1c618ca92
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/xiao/nginx/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/17a9b49be13458de18ce62753d49a94a3d6dc6685af7483f6e9b2e12d20bb92c/merged\\\" at \\\"/var/lib/docker/overlay2/17a9b49be13458de18ce62753d49a94a3d6dc6685af7483f6e9b2e12d20bb92c/merged/etc/nginx/nginx.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.
Problem is due to $PWD/conf/nginx.conf exists in your container, and command docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf ... is trying to replace nginx.conf in your container with nginx.conf from your host.
If you want to have a nginx server in your container with your host's nginx.conf configuration, you have to assure yourself that nginx.conf doesn't exist in container.
If it exists in containers because you're installing it in Dockerfile and you want to keep in container your host nginx.conf file anyway, you need add RUN rm -f $PWD/conf/nginx.conf to your container Dockerfile after nginx installation.
Note that I'm only showing you a possible solution for your proposal, but I cannot recommend you to do it until I know why do you need to use your nginx.conf into the file.

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