[英]Docker volume mounting empty
I'm making an image to host a PHP application.我正在制作一个图像来托管一个 PHP 应用程序。 I'm using
COPY
to populate /var/www/html
with the app files and creating a VOLUME /var/www/html
to be able to mount the dir on the host and edit files like config.我正在使用
COPY
使用应用程序文件填充/var/www/html
并创建一个VOLUME /var/www/html
以便能够在主机上安装目录并编辑像 config.xml 这样的文件。
But:但:
When I mount the volume on docker-compose.yml, the directory is empty.当我在 docker-compose.yml 上挂载卷时,目录为空。
When I omit the "volmue" entry on the docker-compose.yml and connect with the container shell, the directory /var/www/html is filled.当我省略 docker-compose.yml 上的“volmue”条目并与容器 shell 连接时,目录 /var/www/html 被填充。
I already read tons of examples and documentations but, sincerely, don't know what is wrong.我已经阅读了大量的示例和文档,但是,真诚地,不知道出了什么问题。
dockerfile: dockerfile:
FROM php:8.0-apache-buster
LABEL description="OCOMON 3.2 Frontend (noDB)"
RUN docker-php-ext-install pdo_mysql
WORKDIR /var/www/html/ocomon
COPY ./ocomon .
VOLUME /var/www/html/ocomon
docker-compose.yml: docker-compose.yml:
version: '3.5'
services:
ocomon:
image: ocomon:3.2
container_name: ocomon
volumes:
- ./volumes/ocomon/ocomon:/var/www/ocomon
ports:
- 4682:80
Assuming your host's directory is ${PWD}/www/html
, then you need only provide the volumes
value in docker-compose.yml
and it should be:假设您的主机目录是
${PWD}/www/html
,那么您只需要在docker-compose.yml
中提供volumes
值,它应该是:
Dockerfile
: Dockerfile
:
FROM php:8.0-apache-buster
LABEL description="OCOMON 3.2 Frontend (noDB)"
RUN docker-php-ext-install pdo_mysql
WORKDIR /var/www/html/ocomon
COPY ./www/html/ocomon .
and: docker-compose.yml
:和:
docker-compose.yml
:
version: '3.5'
services:
ocomon:
image: ocomon:3.2
container_name: ocomon
volumes:
- ${PWD}/www/html:/var/www/html
ports:
- 4682:80
Dockerfile VOLUMES
creates a volume in the image. Dockerfile
VOLUMES
在图像中创建一个体积。 By following WORKDIR
(which always create if the path does not exist), with VOLUME
, you overwrite whatever was either in (or created by WORKDIR
).通过遵循
WORKDIR
(如果路径不存在则始终创建),使用VOLUME
覆盖其中的任何内容(或由WORKDIR
创建的)。 NOTE this is done during image build .注意这是在图像构建期间完成的。
Docker Compose volumes
mounts a directory from the host into the image. Docker Compose
volumes
将主机中的目录挂载到映像中。 The syntax is volumes: - ${HOST_PATH}:${IMAGE_PATH}
.语法是
volumes: - ${HOST_PATH}:${IMAGE_PATH}
。 NOTE this is done during image run .注意这是在图像运行期间完成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.