同一目录中的多个.dockerignore文件 [英] Multiple .dockerignore files in same directory
问题描述
在同一目录中,我有两个 Dockerfiles
,我想为每个目录分别添加一个 .dockerignore
In the same directory I have two Dockerfiles
and I would like to add a separate .dockerignore
for each of them.
当前,我有:
Dockerfile.npm
Dockerfile.nginx
但是我可以有这样的东西吗?:
But can I have something like this?:
.dockerignore.npm
.dockerignore.nginx
推荐答案
我认为您无法在构建时指定其他忽略文件。但是由于要创建单独的文件,因此可以编写Shell脚本
I don't think you can specify a different ignore file while doing a build. But since you are creating a separate file, you can write a shell script
build_nginx.sh
#!/bin/bash
ln -fs .dockerignore.nginx .dockerignore
docker build -f Dockerfile.nginx -t nginxbuild .
build_npm.sh
#!/bin/bash
ln -fs .dockerignore.npm .dockerignore
docker build -f Dockerfile.npm -t npmbuild .
如果需要与 docker-compose $ c $一起使用c>然后您需要为ngixn和npm分开文件夹,然后可以使用它们各自的
.dockerignore
文件。在您的 docker-compose.yml
文件中,需要指定目录名称作为上下文
If you need to use it with docker-compose
then you need to separate folders for ngixn and npm and then can have their individual .dockerignore
file. In your docker-compose.yml
file you need specify the name of the directory as the context
这篇关于同一目录中的多个.dockerignore文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!