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.
Related
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?
I have a container started as the following:
docker run --interactive --tty --gpus all --name my_container
--workdir "/home/ubuntu" --user ubuntu
--volume /hdd/all_cv/paiv/metis:/home/ubuntu/my --publish 8888:8888 my
how do I run interactively with my_container once I reboot my machine?
Based on the docker documentation, you can attach back to the detached container using docker attach command:
Use docker attach to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.
So you should try this to have an interactive session with your already running container:
docker attach my_container
If your container is stopped, you just need to start it again
docker ps -aq -f name=my_container | xargs docker start $1
I am trying to buld a simple docker file that has a debian image.
Also, I want to mount my local volume inside the docker container.
The problem I have is that how do I get inside the container to see the volume mounted.
$docker run -d -it bash --mount type=bind,source="$(pwd)",target=/app docker_test:latest
43db16a76d50f1da0f8589c9ec460080ccef40122c9bc54abad3230dbbfe7885
I believe this 43db16a.. is container id. Even I try to attach to this container id I get an an error message. It says you cannot attach to the stop container. What am I missing here.
It works if I do
docker run -d -it --name test_docker1 --mount type=bind,source="$(pwd)"/,target=/app docker_test:latest
and then
docker attach
d6bd3cc6dc667e742d0bb3c7fbec58935046c1bf7a2e0b6806d48817082c05be
Also, it works when I do
$docker run --rm -ti --mount type=bind,source="$(pwd)"/,target=/app docker_test:latest
In another terminal do a docker ps, then look for the image you are looking for and copy the id, then do a docker exec -ti <your-image> bash there you have a bash terminal inside the container and you can check the mounted volume.
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!
I have Docker installed in top of a CentOS system.
I tried to use volume but each new container is deleting (or hidding) the content of the folder to share.
My volume is always empty after a Docker run.
In order to create my containers, I use
docker run -dit --name $CONTAINER_NAME -p $PORT:8080 \
-v $VOLUME_PATH:/opt/conf/ \
$IMAGE_NAME
I aim at sharing a folder from the host between few Docker containers (to READ) AND I want also to write into this folder from the host.
What is an elegant way to do that ?
One solution is to use Data Volume Containers.
First, create a data volume container
docker run -d --name <data-volume-name> -v /<data-volume-name> ubuntu
You can add any data you want in this container.
Create your containers that will share by using the option volume-from
Let's create container foo and container bar using the shared datacontainer :
docker run -it --name foo --volumes-from=<data-volume-name> ubuntu
docker run -it --name bar --volumes-from=<data-volume-name> centos
Enjoy yourself
Each container in my example is mapped to the root folder.
From either bar or foo you can see /, in the filesytem.
You can also use volume field.
Create a volume
docker volume create --name <volume-name>
Create containers foo and bar that witl be mapped to the volume
docker run -dit --name foo -v test-volume:/path/in/container/ <image-name>
docker run -dit --name bar -v test-volume:/path/in/container/ <image-name>
Each container that will write in the volume will be visible by other.