How can I add a volume to an existing Docker container?

You can commit your existing container (that is create a new image from container’s changes) and then run it with your new mounts.

Example:

$ docker ps  -a

CONTAINER ID        IMAGE                 COMMAND                  CREATED              STATUS                          PORTS               NAMES
5a8f89adeead        ubuntu:14.04          "/bin/bash"              About a minute ago   Exited (0) About a minute ago                       agitated_newton

$ docker commit 5a8f89adeead newimagename
$ docker run -ti -v "$PWD/somedir":/somedir newimagename /bin/bash

If it’s all OK, stop your old container, and use this new one.

That´s it 🙂

Leave a Comment