Mounting multiple directory's as an external volume - Docker - docker

I am trying to run a Nginx Docker container with 3 directorys mounted as an external volume. When I mount just one the container is up and and running but when I mount 3 the container is created and then exits right away.
docker run -v ~/data/usr:/usr/share/nginx/ -v ~/data/etc:/etc/nginx/ -v ~/data/var:/var/log/nginx/ -d -p 80:80 --name webserver nginx
Any ideas?

Related

In Docker share volume between two running container

When I create container and attach to volume, I need to stop this container running before I attach the same volume to other container in docker. How I can share volume between two running container.
docker run --detach --name mariadb-1 --env MARIADB_ROOT_PASSWORD=root
-v new-volume:/var/lib/mysql mariadb.
docker run --detach --name mariadb-2 --env MARIADB_ROOT_PASSWORD=root
-v new-volume:/var/lib/mysql mariadb.
When I access mariadb-1 container, the container mariadb-2 exit by-itself. and when I access mariadb-2 container, it will not be accessed and I get a message that it's not running.

Docker shared volumes create and attach problem

I've a question about docker shared volumes.
I know that if I run a container with -v option I create a volume that I can share to another container with --volumes-from:
docker run -d -v DataVolume1:/datavolume1 --name container1 image1:v1.0.0
docker run --name container2 --volumes-from container1 image2:v1.0.0
But I cannot understand the full behaviour of this. It seems like volume from container 1 is a master and the same volume in container 2 is a slave. So container 2 can write and container 1 read or only the opposite?
Why I cannot use -v option on all my container like that?
docker run -d -v DataVolume1:/datavolume1 --name container1 image1:v1.0.0
docker run -d -v DataVolume1:/datavolume1 --name container2 image2:v1.0.0
or create a volume with:
docker volume create --name DataVolume1
and then attach to the two container with:
docker run -d -v DataVolume1:/datavolume1 --name container1 image1:v1.0.0
docker run -d -v DataVolume1:/datavolume1 --name container2 image2:v1.0.0
Is there some trouble because each -v recreate the volume and cut the link with the previous container? Or something other?
Because with two "docker run -v" I could also specify different mounting path for the same volume, so if it work for me is better, but I never see anyone use this way so what's the problem?
Thanks in advance!

Apache website not updating after restarting docker

I have created an apache2 docker container
docker run -dit --name tecmint-web -p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4
This is working. but if I stop this container and start again by docker restart <container-id>. It does not pick new html file from my /home/user/website/.
How can I realign these 2 directories after restarting docker?

Docker container to use same Nexus volume?

I run the following:
mkdir /some/dir/nexus-data && chown -R 200 /some/dir/nexus-data
chown -R 200 /Users/user.name/dockerVolume/nexus
docker run -d -p 8081:8081 --name nexus -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
Now lets say I upload an artifact to Nexus, and stop the nexus container.
If I want another Nexus container open, on port 8082, what Docker command do I run such that it uses the same volume as on port 8081 (so when I run this container, it already contains the artifact that I uploaded before)
Basically, I want both Nexus containers to use the same storage, so that if I upload an artifact to one port, the other port will also have it.
I ran this command, but it didn't seem to work:
docker run --name=nexus2 -p 8082:8081 --volumes-from nexus sonatype/nexus3
Bind mounts which is what you're using as a "volume" has limited functionality as compared to an explicit Docker volume.
I believe the --volumes-from flag only works with volumes managed by Docker.
In order to share the volume between containers with this flag you can have docker create a volume for you with your run command.
Example:
$ docker run -d -p 8081:8081 --name nexus -v nexus-volume:/nexus-data sonatype/nexus3
The above command will create a Docker managed volume for you with the name nexus-volume. You can view the details of the created volume with the command $ docker volume inspect nexus-volume.
Now when you want to run a second container with the same volume you can use the --volumes-from command as you desire.
So doing:
$ docker run --name=nexus2 -p 8082:8081 --volumes-from nexus sonatype/nexus3
Should give you your desired behaviour.

Share Same resource in multiple Container in docker

I need to setup one container volume use to multiple container.
for example:
Container 1(web app1): volume path -v /var/www/html/
Container 2 (web app2): volume path -v /var/www/html/
Container 3(Commaon Files): volume path -v /var/www/html/
I need to setup Container-3 Common file use other two Containers.
How can I Achive this.
You should name your volumes so you can mount them by name instead of by container. So:
docker run -d --name web1 -v web1-html:/var/www/html web-img
docker run -d --name web2 -v web2-html:/var/www/html web-img
docker run -d --name common -v web1-html:/var/www/web1/html \
-v web2-html:/var/www/web2/html your-img
With the volumes created today from your two web apps, you'll see them listed with a guid under docker volume ls. By giving them a name, you can easily reused those volumes in other containers.

Resources