我正嘗試將代碼從主機分享到php
和nginx
容器。這裏是我的docker-compose.yml
:如何使用命名卷將數據從主機共享到容器?
version: "3"
services:
php:
image: php:fpm
container_name: php
ports:
- 9000:9000
volumes:
- php_data:/var/www/html/
# configs
- ./php/config:/usr/local/etc/php
nginx:
image: nginx
ports:
- 80:80
volumes:
- php_data:/var/www/html
# logs
- ./nginx/logs:/var/log/nginx
# configs
- ./nginx/config/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./nginx/config/nginx.conf:/etc/nginx/nginx.conf:ro
volumes:
php_data:
./code
錯誤時運行docker-compose up
是:
ERROR: In file './docker-compose.yml', volume 'php_data' must be a mapping not a string.
我如何做搬運工,撰寫知道,我需要./code
既nginx
和PHP containers
共享?
它不回答你的問題,但如果這是足以讓你分享的容器,而不是主機的體積,你可以去掉最後一行「./code」如[documentation]中所示(https://docs.docker.com/compose/compose-file/#volume-configuration-reference) – herm