-1

How would I go about starting a container with a volume that's already created? I have a volume for example named 'data' and 'docker volume ls' will show this. Now I need to start a container by attaching this existing volume.

xelber
  • 4,197
  • 3
  • 25
  • 33

1 Answers1

1

Mounting a Data Volume

To mount a data volume to a container add the --mount flag to the docker run command. It adds the volume to the specified container, where it stores the data produced inside the virtual environment.

To run a container and mount a data volume to it, follow the basic syntax:

docker run --mount source=[volume_name],destination=[path_in_container] 

Replace [path_in_container] with the path where you want to place the data volume in the container. Everything stored in that directory automatically gets saved on the data volume on the host as well.

For example, to launch an Ubuntu container and mount the data volume to it, run:

docker run -it --name=example1 --mount source=data,destination=/data ubuntu
mahen3d
  • 7,047
  • 13
  • 51
  • 103