0

I need to attach a volume to the running container which has started from the docker run command on my AWS EC2 server (Ubuntu 18.04 LTS) with the following command

$ docker run --name example -p 8080:80 -dt example-image:latest

I'm using Docker version 19.03.12.

Jay Blanchard
  • 33,530
  • 16
  • 73
  • 113
saikrishna
  • 13
  • 3
  • 1
    You have to delete and recreate the container with a new `docker run` command. Note that you need to do this for many other common tasks too (especially running the container with a newer image) and I'd treat this as totally routine. – David Maze Sep 29 '20 at 14:24
  • Look at https://stackoverflow.com/questions/28302178/how-can-i-add-a-volume-to-an-existing-docker-container/56970321#56970321 – droebi Oct 12 '20 at 14:26

1 Answers1

0

You should stop/delete the existing container and run the container with a command containing the volume mount command. You can use the -v flag:

$ docker run --name example -v <name of local volume>:<docker image path> -p 8080:80 -dt example-image:latest
Jay Blanchard
  • 33,530
  • 16
  • 73
  • 113
  • 1
    That's not the question(?). Running a new container bind-mounting a `volume` is easy however mounting a `volume` to an already running container not so much, [this](https://jpetazzo.github.io/2015/01/13/docker-mount-dynamic-volumes/) looks like what OP needs. – masseyb Sep 29 '20 at 14:12