我的船坞-组合定义了两个容器。我希望一个容器与另一个容器共享一个卷。
version: '3'
services:
web-server:
env_file: .env
container_name: web-server
image: web-server
build:
dockerfile: docker/Dockerfile
ports:
- 3000:3000
- 3500:3500
volumes:
- static-content: /workspace/static
command: sh /workspace/start.sh
backend-server:
volumes:
- static-content: /workspace/static
volumes:
static-content:上面的文件声明了两个服务,web服务器和后端服务器。我在“服务”下声明了命名的卷static-content。运行docker-composer -f docker-composer.yml up时出现以下错误
services.web-server.volumes contains an invalid type, it should be a string
services.backend-server.volumes contains an invalid type, it should be a string那么,我如何分享卷抛码头-作曲家?
发布于 2017-11-06 12:38:41
您需要使用没有空格的docker卷语法。
<local_path>:<service_path>:<optional_rw_attributes>例如:
./:/your_path/将当前工作目录映射到/your_path。
这个例子是:
./:/your_path/:ro将当前工作目录映射到具有只读权限的/your_path。
阅读这些文档以获得更多信息:https://docs.docker.com/compose/compose-file/#volume-configuration-reference
发布于 2017-11-06 14:30:52
卷字符串中有一个额外的空间,这将导致Yaml将解析从字符串数组更改为名称/值映射数组。删除卷条目中的空格(请参见下面),以防止此错误:
version: '3'
services:
web-server:
env_file: .env
container_name: web-server
image: web-server
build:
dockerfile: docker/Dockerfile
ports:
- 3000:3000
- 3500:3500
volumes:
- static-content:/workspace/static
command: sh /workspace/start.sh
backend-server:
volumes:
- static-content:/workspace/static
volumes:
static-content:有关更多细节,请参见撰写卷短语法的文件部分。
https://stackoverflow.com/questions/47136748
复制相似问题