Docker Ignore is not woking well with docker compose and my file structure

馋奶兔 提交于 2019-12-05 22:01:35

At build time, the directive COPY . . (inside the Dockerfile) correctly copies all files not listed in .dockerignore in $RAILS_ROOT (inside the image). No problem here (check that by running docker run --rm custom-web:1.0 ls -al).

But here you run docker-compose to start the container, and you have defined a volume :

volumes:
    - .:/var/www/${APP_NAME}_web

That means that files from the same directory as docker-compose.yml are shared between the host and the container. That's why you find all files (even those listed in .dockerignore) in $RAILS_ROOT (workdir of custom-web:1.0 image) after starting the container via docker-compose.

If you really need to share files between your host and the container (via a volume), I'll suggest you to mount the current directory in another location than the one specified in your Dockerfile, like :

volumes:
    - .:/${APP_NAME}_web

Otherwise, using COPY . . and a volume is redundant here.

I faced the same problem with docker build, node_modules directories were not being ignored.

SOLUTION
Changing node_modules to **/node_modules inside .dockerignore solved my issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!