Skip to content

Instantly share code, notes, and snippets.

@agail
Last active June 9, 2023 12:51
Show Gist options
  • Save agail/276d8a41390ab27424d5efc884fffab3 to your computer and use it in GitHub Desktop.
Save agail/276d8a41390ab27424d5efc884fffab3 to your computer and use it in GitHub Desktop.
Add docker volume to running container

Source: https://stackoverflow.com/questions/28302178/how-can-i-add-a-volume-to-an-existing-docker-container#comment98804407_53516263

* docker ps --no-trunc --format 'table {{.ID}}\t{{.Names}}'      # list running containers and their id's
* cd /var/lib/docker/containers/<container id>                   # cd to desired container
* systemctl stop docker.service                                  # otherwise changes will be overwritten when re-starting
* vim <(jq . config.v2.json)                                     # prettify json and load it into vim / vi
* :/MountP                                                       # search for MountPoints

 "MountPoints": {
    "/app/dockerdir": {
      "Source": "/home/myuser/dockerdir",
      "Destination": "/app/dockerdir",
      "RW": true,
      "Name": "",
      "Driver": "",
      "Type": "bind",
      "Propagation": "rprivate",
      "Spec": {
        "Type": "bind",
        "Source": "/home/myuser/dockerdir/",
        "Target": "/app/dockerdir/"
      },
      "SkipMountpointCreation": false
    },

* Add insert additional mounts
* :wq! config.v2.json                             # save and config.v2.json and quit
* systemctl start docker.service                  # start docker service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment