Can a .dockeringore file include a volume folder?

谁都会走 提交于 2019-12-11 15:05:40

问题


Imagine a project folder like this:

  • project_folder
    • source_code_folder_1
    • docker_volume_folder
    • source_code_file_1
    • Dockerfile
    • docker-compose.yml
    • .dockerignore

Now, if

  • the Dockerfile contains an instruction ADD . /code/, and
  • if the docker-compose.yml file configures a service that uses the docker_volume_folder in its volume mapping,

can I then add the docker_volume_folder in the .dockerignore file, to prevent that the volume folder is copied to the docker container by the ADD . /code/ instruction in the dockerfile?

I think adding the docker volume folder to the docker container is not only useless, maybe it's even dangerous. However, I want to avoid that Docker Compose does not want to create the volume, since it is mentioned in the .dockerignore file.

I can't find information about volumes in the dockerignore in the documentation.


回答1:


You can include the directory in your .dockerignore file, that only affects the build, not the later volume mounts.

The only reason you may want to include the directory inside your image is if you want named volumes to be initialized with the contents of the image. If you only use host volumes, this will not be an issue.



来源:https://stackoverflow.com/questions/50744707/can-a-dockeringore-file-include-a-volume-folder

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