CLIコマンドを使用したDockerボリュームのマウント

CLIコマンドを使用したDockerボリュームのマウント

2つのフォルダ/etc/phpとコンテナ/var/wwwの内容を保存するために使用したい2つのボリュームを作成しました。

$ docker volume create dvwa_etcphp
$ docker volume create dvwa_www

コンテナがあり、次のように実行します。

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

しかし、私がこれを行うと:

$ docker inspect c70

それは私に提供します(私は私に重複するすべてを削除しました):

[
    {
        "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]"
            }
        },
    }
]

/etc/phpボリュームを使用して両方のフォルダに変更を保存したいと思います/var/www。コンテナーを停止して新しいコンテナーを実行するときは、編集した構成ファイルでこれら2つのボリュームを使用したいと思います。

Dockerのバージョンは19.03.2です。

ありがとうございます!

ベストアンサー1

次の形式で作成できます。

 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>

編集する:Createコマンドが編集されました

上記は私にとって効果的です。

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"
            }
        ]

可能であれば詳細な出力を提供します。

おすすめ記事