[英]Why docker container can't see volume on different container?
我有 2 個使用 docker-compose up 啟動的容器。 第一個我只是從 docker hub nginx:stable 中提取的第二個我建立在來自 hub 的 php 之上
文件
FROM composer:1.9.3
RUN mkdir /fatfree
RUN ["composer","require","bcosca/fatfree-core","--working-dir","/fatfree"]
FROM php:7.4-fpm
COPY --from=0 /fatfree /fatfree
我也在上面的文件中嘗試了VOLUME /fatfree
無濟於事。
docker-compose.yml
version: "3.7"
services:
webserver:
image: nginx:stable
ports:
- "80:8080"
volumes:
- ./www:/www
- fatfree:/fatfree
links:
- php
php:
build:
context: .
dockerfile: dockerfile
volumes:
- ./www:/www
- "fatfree:/fatfree"
volumes:
fatfree:
如果我正確解釋了 docker 文檔,我的www/index.php
應該能夠看到 /fatfree 中的任何內容,但它沒有。 文件夾本身顯示出來,但看起來是空的。
如果我以交互方式運行 dockerfile docker docker container run -i -t test bash
, /fatfree
文件夾存在並且它包含我希望它擁有的所有文件。
有很多 stackoverflow 問題詢問如何實現這一點,它們似乎都表明我正在做的實際上沒問題,但它不起作用,我不知道為什么。 任何建議表示贊賞。
您的映射不正確。
你要:
volumes:
- /fatfree:/www
第一個條目/fatfree
指的是主機上的路徑。
第二個條目/www
指的是容器中的路徑。
在我的示例中,您主機的/fatfree
目錄(和內容)將映射到容器的/www
目錄。
根據需要更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.