1

I've created two volumes I wish to use to store content of two folders /etc/php and /var/www inside of container:

$ docker volume create dvwa_etcphp
$ docker volume create dvwa_www

I have a container, which I run using the command:

docker run --rm -it -p 80:80 vulnerables/web-dvwa --name dvwatest \
--mount type=volume,source=dvwa_www,target=/var/www \
--mount type=volume,source=dvwa_etcphp,tagret=/etc/php

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                NAMES
c700546a86b7        vulnerables/web-dvwa   "/main.sh --name dvw…"   4 minutes ago       Up 4 minutes        0.0.0.0:80->80/tcp   quirky_hawking

But when I do:

$ docker inspect c70

it gives me (I've removed everything that seem to me superfluos):

[
    {
        "Id": "c700546a86b74de5f2f941ee92fd72406e2a29e2e06ca85532658d1fa6ddbae5",
        "Created": "2020-01-22T13:36:23.976013357Z",
        "Path": "/main.sh",
        "Args": [
            "--name",
            "dvwatest",
            "--mount",
            "type=volume,source=dvwa_www,target=/var/www",
            "--mount",
            "type=volume,source=dvwa_etcphp,tagret=/etc/php"
        ],

        "Name": "/quirky_hawking",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "VolumeDriver": "",
            "VolumesFrom": null,
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "c700546a86b7",
            },
            "Cmd": [
                "--name",
                "dvwatest",
                "--mount",
                "type=volume,source=dvwa_www,target=/var/www",
                "--mount",
                "type=volume,source=dvwa_etcphp,tagret=/etc/php"
            ],
            "Image": "vulnerables/web-dvwa",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/main.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "[email protected]"
            }
        },
    }
]

I want to use volumes to save changes in two folders: /etc/php and /var/www. And when I stop container and run a new one I want it to use these two volumes with edited config files.

Docker version is 19.03.2

Thank you!

3

1 Answer 1

2

Can you try following the following format for creating:

 docker run -it --mount type=volume,src=<VOLUME-NAME>,dst=<CONTAINER-PATH> --mount type=volume,src=<VOLUME-NAME>,dst=<CONTAINER-PATH> -p host_port:container_port --name myservice <IMAGE>

Edit: Creation command has been edited

The above worked for me:

docker run -ti --mount type=volume,src=cust_vol2,dst=/cust_vol2 --mount type=volume,src=cust_vol1,dst=/cust_vol1  -p 8024:8024  --name mycontainer centos

$docker inspect mycontainer
"Mounts": [
            {
                "Type": "volume",
                "Source": "cust_vol2",
                "Target": "/cust_vol2"
            },
            {
                "Type": "volume",
                "Source": "cust_vol1",
                "Target": "/cust_vol1"
            }
        ]

and provide the verbose output if possible.

3
  • Ok. It outputs: Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
    – Gryu
    Jan 22, 2020 at 16:58
  • Sorry @Gryu. Services need swarm cluster to be setup first. In your case you can go ahead with edited command. Jan 22, 2020 at 18:28
  • Yes, now it shows: "Mounts": [ { "Type": "volume", "Name": "dvwa_www", "Source": "/var/lib/docker/volumes/dvwa_www/_data", "Destination": "/var/www", "Driver": "local", "Mode": "z", "RW": true, "Propagation": "" }, ... Thank you!
    – Gryu
    Jan 22, 2020 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .