如何解决使用docker-compose.yml绑定装载时的错误?
我使用下面的docker run命令打开容器如何解决使用docker-compose.yml绑定装载时的错误?,docker,docker-compose,dockerfile,Docker,Docker Compose,Dockerfile,我使用下面的docker run命令打开容器 docker run -p 8080:8080 -v /opt/docker/logs:/opt/components/logs \ --mount type=volume,dst=/opt/components/config,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=/opt/docker/config \ --name ich
docker run -p 8080:8080 -v /opt/docker/logs:/opt/components/logs \
--mount type=volume,dst=/opt/components/config,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=/opt/docker/config \
--name ich --env-file doc.env --env component=sample1 -d ich
我想创建一个docker compose文件来挂载它并打开容器。。。我使用下面的命令,它抛出了一个错误
version: "3"
services:
ich:
image: ich
container_name: ich
hostname: ich
env_file:
- ./doc.env
ports:
- 8080:8080
environment:
component: "sample1"
volumes:
- "/opt/docker/logs:/opt/components/logs"
bind-test:
driver: local
driver_opts:
type: none
o: bind
device: /opt/docker/config
dst: /opt/components/config
我得到了错误
ERROR: yaml.parser.ParserError: while parsing a block collection
in "./docker-compose.yaml", line 14, column 11
expected <block end>, but found '?'
in "./docker-compose.yaml", line 19, column 11
错误:yaml.parser.parserror:在分析块集合时
在“/docker compose.yaml”第14行第11列中
应为,但找到“?”
在“/docker compose.yaml”第19行第11列中
请帮助解决此问题。…您
docker compose
出现语法错误,在编写yaml后,您可以转到验证语法
对于您的情况,driver\u opts
&driver
定义用于跨多个服务重用,应该在顶级卷键下定义,如next
volumes:
bind-test:
driver: local
driver_opts:
device: /opt/docker/config
o: bind
type: none
细节是指
您如何使用它的示例:
version: "3"
services:
ich:
image: ubuntu:18.04
tty: true
stdin_open: true
container_name: ich
hostname: ich
ports:
- 8080:8080
environment:
component: "sample1"
volumes:
- bind-test:/etc
volumes:
bind-test:
driver: local
driver_opts:
type: none
o: bind
device: /opt/docker/config
让我解释一下:假设我将docker compose.yaml
放在foler20210608
中,并使用docker compose up-d
启动容器:
将容器中的-bind test:/etc
映射到具有卷的主机文件系统,位置应为/etc
,您可以在此文件夹中查看容器的/var/lib/docker/volumes/20210608\u bind-test/\u data
的所有内容/etc
- 此外,当您指定
时,还可以在driver\u opts
中看到内容,这些内容装载到/opt/docker/config
/var/lib/docker/volumes/20210608\u bind-test/\u data
- 另外,您可以使用“下一步”检查卷:
- 在主机文件夹中,我可以看到容器的内容:
另外,如果您的环境不干净,您可以使用next:
docker compose down-v
,或者直接删除一些卷以清理使用下一步:docker volume rm 20210608_bind-test
,然后再进行上述实验。厌倦了使用相同的方法,但安装不起作用,因为使用问题中提到的docker run命令时,安装不起作用。@JCDani更新对于您的场景,您应该在服务ich
中定义目标文件夹,不要在driver\u opts
中定义它。容器成功启动,但安装失败。。。我无法查看主机中容器的文件。当前主机空文件夹正在覆盖容器文件否这不是我需要的。。。。如果您看到docker run命令,它会将容器中的文件显示到主机中…这允许用户修改配置,而compose file one则不会这样做。。。我正在尝试使用docker compose文件重新创建docker运行,以实现主机到容器文件的可见性,我相信仅使用标准卷语法就可以了,而且不需要绑定装载。。。你能帮我一点忙吗
$ docker volume ls | grep bind-test
local 20210608_bind-test
$ docker volume inspect 20210608_bind-test
[
{
"CreatedAt": "2021-06-08T09:38:21+08:00",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "20210608",
"com.docker.compose.version": "1.25.4",
"com.docker.compose.volume": "bind-test"
},
"Mountpoint": "/var/lib/docker/volumes/20210608_bind-test/_data",
"Name": "20210608_bind-test",
"Options": {
"device": "/opt/docker/config",
"o": "bind",
"type": "none"
},
"Scope": "local"
}
]
/opt/docker/config$ ls
adduser.conf debconf.conf fstab hosts ld.so.conf lsb-release opt profile.d rc5.d security subuid
alternatives debian_version gai.conf init.d ld.so.conf.d machine-id os-release rc0.d rc6.d selinux sysctl.conf
apt default group issue legal mke2fs.conf pam.conf rc1.d rcS.d shadow sysctl.d
bash.bashrc deluser.conf gshadow issue.net libaudit.conf mtab pam.d rc2.d resolv.conf shells systemd
bindresvport.blacklist dpkg host.conf kernel login.defs networks passwd rc3.d rmt skel terminfo
cron.daily environment hostname ld.so.cache logrotate.d nsswitch.conf profile rc4.d securetty subgid update-motd.d