Ignoring files and directories with .dockerignore

荒凉一梦 提交于 2021-02-10 18:19:03

问题


I have a simple .dockerignore file with the following:

.git/
.idea/
venv/

My docker-compose.yml file mounts the volume:

version: "3"
services:
  frontend:
    build: .
    command: ["gunicorn", "--bind", "0.0.0.0:8000",  "project.app:create_app()"]
    env_file:
      - .env
    volumes:
      - .:/frontend
    ports:
      - "8000:8000"

Perhaps I don't understand the full syntax or intent of the .dockerignore file, but after running docker-compose up --build, .git/, .idea/ and venv/ end up in my container.

I've read up and saw this but it doesn't seem feasible that one cannot mount and prevent files and directories from landing in the container.

How do I prevent these directories from becoming available in the container?


回答1:


The .dockerignore file will modify the context that is sent to the docker daemon to build the image. So the created image will not have these files inside unless you recreate them.

The volume mount is completely separate and a host volume mount, aka bind mount, will map the contents of the host directory directly into the container as is. This is a Linux OS level activity that doesn't follow .dockerignore.

You will need to exclude those files from the directory that you mount into the container, or not mount the volume into the container and rely on the image to take advantage of .dockerignore.



来源:https://stackoverflow.com/questions/50135714/ignoring-files-and-directories-with-dockerignore

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