User Tools

Site Tools


linux:docker

This is an old revision of the document!


Docker

https://docs.docker.com/storage/volumes/

Copying files from/to images

docker cp dockerimage:/bla ./bla
docker cp ./bla dockerimage:/bla

Change mount points of existing docker containers;

e.g. mount /home/<user-name> folder of host to the /mnt folder of the existing (not running) container.

  1. stop docker container or whole docker engine
    systemctl stop docker.service
  2. Open configuration file corresponding to the stopped container, which can be found at /var/lib/docker/containers/99d…1fb/config.v2.json (may be config.json for older versions of docker). For pretty print use
    vi <(jq . /var/lib/docker/containers/<container-ID>/config.v2.json)
    Save updates to a file: :w config.v2.json
    Exit vim: :q!
    Update existing file: jq -c . config.v2.json > /var/lib/docker/containers/<container-ID>/config.v2.json
     
  3. Find MountPoints section: “MountPoints”:{}.
  4. Replace the contents with something like this (you can copy proper contents from another container with proper settings):
    "MountPoints":{"/mnt":{"Source":"/home/<user-name>","Destination":"/mnt","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/home/<user-name>","Target":"/mnt"},"SkipMountpointCreation":false}}

    or the same (formatted):

      "MountPoints": {
        "/mnt": {
          "Source": "/home/<user-name>",
          "Destination": "/mnt",
          "RW": true,
          "Name": "",
          "Driver": "",
          "Type": "bind",
          "Propagation": "rprivate",
          "Spec": {
            "Type": "bind",
            "Source": "/home/<user-name>",
            "Target": "/mnt"
          },
          "SkipMountpointCreation": false
        }
      }
  5. Start or restart the docker service:
    systemctl start docker.service
    service docker restart
  6. Start the container if necessary:
    docker start <container-name/ID>
linux/docker.1684874900.txt.gz · Last modified: 2023/05/29 11:53 (external edit)