How to name Dockerfiles

2019-03-08 17:30发布

I'm unsure of how to name Dockerfiles. Many on GitHub use Dockerfile without a file extension. Do I give them a name and extension; if so what? Or do I just call them Dockerfile?

8条回答
相关推荐>>
2楼-- · 2019-03-08 17:38

If you want to use the autobuilder at hub.docker.com, it has to be Dockerfile. So there :)

查看更多
Juvenile、少年°
3楼-- · 2019-03-08 17:40

Do I give them a name and extension; if so what?

You may name your Dockerfiles however you like. The default filename is Dockerfile (without an extension), and using the default can make various tasks easier while working with containers.

Depending on your specific requirements you may wish to change the filename. If you're building for multiple architectures, for example, you may wish to add an extension indicating the architecture as the resin.io team has done for the HAProxy container their multi-container ARM example:

Dockerfile.aarch64
Dockerfile.amd64
Dockerfile.armhf
Dockerfile.armv7hf
Dockerfile.i386
Dockerfile.i386-nlp
Dockerfile.rpi

In the example provided, each Dockerfile builds from a different, architecture-specific, upstream image. The specific Dockerfile to use for the build may be specified using the --file, -f option when building your container using the command line.

查看更多
小情绪 Triste *
4楼-- · 2019-03-08 17:44

On vscode, I use dev.Dockerfile and it still recognizes it correctly.

So my strategy for naming multiple Dockerfiles in the same folder is:

purpose.Dockerfile

查看更多
Animai°情兽
5楼-- · 2019-03-08 17:51

Don't change the name of the dockerfile if you want to use the autobuilder at hub.docker.com. Don't use an extension for docker files, leave it null. File name should just be: (no extension at all)

Dockerfile
查看更多
放我归山
6楼-- · 2019-03-08 17:51

I think you should have a directory per container with a Dockerfile (no extension) in it. For example:

  /db/Dockerfile
  /web/Dockerfile
  /api/Dockerfile

When you build just use the directory name, Docker will find the Dockerfile. e.g:

docker build -f ./db .
查看更多
太酷不给撩
7楼-- · 2019-03-08 17:51

Dockerfile is good if you only have one docker file (per-directory). You can use whatever standard you want if you need multiple docker files in the same directory - if you have a good reason. In a recent project there were AWS docker files and local dev environment files because the environments differed enough:

Dockerfile Dockerfile.aws

查看更多
登录 后发表回答