.dockerignore不会忽略列出的文件夹和文件

问题描述 投票:0回答:1

这就是我的文件夹结构的样子

- myapp
-- public
-- other_dirs
-- docker // contain all the Dockerfiles and configuration files etc
-- vendor
-- .gitignore
-- .dockerignore
-- README.md

在Dockerfile中,我使用此方法来复制容器中的所有应用程序

FROM php:7.1-apache-stretch

COPY . /var/www/html

WORKDIR /var/www/html/

这是docker-compose文件

version: '3'

services:
    app:
        image: myapp
        build:
             context: .
             dockerfile: docker/Dockerfile
        volumes:
            - .:/var/www/html
        ports:
            - 8080:80
        networks:
            - appnet

这就是我的.dockerignore文件的样子

.git
.gitignore
vendor/

当我运行docker-compose up --build然后exec进入我的应用程序容器时,如果我执行ls -lah,我仍然可以在列表中看到我在.dockerignore文件中添加的文件夹和文件。我有什么想法我做错了吗?

docker
1个回答
0
投票

您正在查看这些文件,因为您正在将卷装入目录中。要解决它,请看看:Make docker-compose ignore folder within volume

© www.soinside.com 2019 - 2024. All rights reserved.