How do I start a Docker container with a volume?

0 votes
Jul 2 in Docker by Sirajul
• 38,420 points
129 views

1 answer to this question.

0 votes

You can first create the volume and then start the container or .If you are trying to start a container with a volume that doesn't exist, docker will create a volume for you. Suppose you want to mount a volume (say vol1) into /app/ of the container (say mycontainer1).

You can do this either by using -v or --mount. Here's how you can do it.

$ docker run -d \
  --name mycontainer1 \
  --mount source=vol1,target=/app \
  ubuntu:latest

You can achieve the same using -v instead of --mount as shown below:

$ docker run -d \
  --name mycontainer1 \
  -v vol1:/app \
  ubuntu:latest

Either of these would do!

answered Jul 2 by Namik
• 1,210 points

Related Questions In Docker

0 votes
2 answers

How do I start a container and create a volume using a volume driver?

You can first create the volume and ...READ MORE

answered Aug 6 in Docker by Sirajul
• 38,420 points
37 views
0 votes
1 answer

How to base a docker volume with docker container?

Run the following command: docker run -d --volumes-from ...READ MORE

answered Aug 5, 2018 in Docker by Sophie may
• 9,870 points
96 views
0 votes
1 answer

How do I get into a Docker container?

docker attach will let you connect to your ...READ MORE

answered Aug 10, 2018 in Docker by Kalgi
• 42,430 points
67 views
0 votes
1 answer

How do I copy a file from docker container to host?

Here is a way which you can ...READ MORE

answered Aug 27, 2018 in Docker by Damon Salvatore
• 5,510 points
3,838 views
0 votes
2 answers

How do I run a docker image as a container?

You could probably follow these steps : $ docker ...READ MORE

answered Aug 9 in Docker by Sirajul
• 38,420 points
127 views
+1 vote
1 answer
0 votes
1 answer

What is a docker file? How do I create a docker image with dockerfile?

 A Dockerfile is a script/text configuration file that contains ...READ MORE

answered Jun 7 in Docker by Sirajul
• 38,420 points
386 views
0 votes
1 answer
+1 vote
11 answers

How can I run a ‘docker exec’ command inside a docker container?

Use bash with -c docker exec -it CONTAINER_ID ...READ MORE

answered Dec 10, 2018 in Docker by Kiyara
125,136 views