我创建了两个卷,我希望用它来存储两个文件夹/etc/php
和/var/www
容器内部的内容:
$ 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
. 当我停止容器并运行一个新容器时,我希望它使用这两个带有已编辑配置文件的卷。
Docker 版本是 19.03.2
谢谢!
您可以尝试按照以下格式进行创建:
编辑:创建命令已被编辑
以上对我有用:
并尽可能提供详细的输出。