How to name Dockerfiles

前端 未结 10 972
谎友^
谎友^ 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:52

    Dockerfile (custom name and folder):

       docker/app.Dockerfile
       docker/nginx.Dockerfile
    

    Build:

       docker build  -f ./docker/app.Dockerfile .
       docker build  -f ./docker/nginx.Dockerfile .
    
    0 讨论(0)
  • 2020-12-22 22:56

    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

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

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

    It seems this is true but, personally, it seems to me to be poor design. Sure, have a default name (with extension) but allow other names and have a way of specifying the name of the docker file for commands.

    Having an extension is also nice because it allows one to associate applications to that extension type. When I click on a Dockerfile in MacOSX it treats it as a Unix executable and tries to run it.

    If Docker files had an extension I could tell the OS to start them with a particular application, e.g. my text editor application. I'm not sure but the current behaviour may also be related to the file permisssions.

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