How to name Dockerfiles

前端 未结 10 982
谎友^
谎友^ 2020-12-22 22:17

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 ca

相关标签:
10条回答
  • 2020-12-22 22:35

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

    0 讨论(0)
  • 2020-12-22 22:35

    I have created two Dockerfiles in same directory,

    # vi one.Dockerfile
    # vi two.Dockerfile
    

    to build both Dockerfiles use,

    # docker build . -f one.Dockerfile
    # docker build . -f two.Dockerfile
    

    Note: you should be in present working directory..

    0 讨论(0)
  • 2020-12-22 22:39

    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
    
    0 讨论(0)
  • 2020-12-22 22:44

    dev.Dockerfile, test.Dockerfile, build.Dockerfile etc.

    On VS Code I use <purpose>.Dockerfile and it gets recognized correctly.

    0 讨论(0)
  • 2020-12-22 22:50

    I know this is an old question, with quite a few answers, but I was surprised to find that no one was suggesting the naming convention used in the official documentation:

    $ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug .
    $ docker build -f dockerfiles/Dockerfile.prod  -t myapp_prod .
    

    The above commands will build the current build context (as specified by the .) twice, once using a debug version of a Dockerfile and once using a production version.

    In summary, if you have a file called Dockerfile in the root of your build context it will be automatically picked up. If you need more than one Dockerfile for the same build context, the suggested naming convention is:

    Dockerfile.<purpose>
    

    These dockerfiles could be in the root of your build context or in a subdirectory to keep your root directory more tidy.

    0 讨论(0)
  • 2020-12-22 22:52

    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.

    0 讨论(0)
提交回复
热议问题