Docker options for chaining dockerfiles

I would love to make reusable dockerfiles. I don’t see anyway to do this since there are no variables and no include option correct? Anyone have a good option (besides dyanmically creating / modifying the dockerfile and build time)?

Would love to be able to resuse production env dockerfiles since there is 1 per service (ex: 1 web app, 1 database, 1 cache, etc) and build all of them on the same image so I can run a full app in 1 container (1 possible use case is running multiple feature branches on a single server).

  • Golang Dockerfile Failing
  • How to change sbt-docker settings to choose an specific route for artifacts
  • Docker Image can't execute command
  • How do I push an image to my NON-public repo in dockerhub
  • Meteor Spawn Error ENOENT
  • Docker, referencing a differnet container. Call mysqldump using php command
  • Yeah I know I could build each container separately and link them but seems like total over kill for setup and managing (since in some cases may need 6 or more containers for a single feature branch).

  • Writing python log files to logstash
  • Docker -v paramter limited in size
  • Somtimes docker container dns fail
  • Docker-Compose build failing on Google App Engine
  • Docker build ADD vs RUN curl
  • How to run Swagger Spring Application using Jetty on Docker
  • 3 Solutions collect form web for “Docker options for chaining dockerfiles”

    If you do not want to create multiple images you can always create a monster image with everything installed in it. In my opinion, that is a code smell, but it is possible. In case you will never split up the services across servers this might even be valid.

    If you want to use the same kind of image in different contexts, you can use environment variables to parameterize behavior and still use the same image. For instance, have a bash script that expects YOUR_VARIABLE and the start your container using the -e option (see the documentation). E.g.

    docker run -e "YOUR_VARIABLE=value" --rm ubuntu env

    There are tools such as fig that make bringing up a number of containers easy. You still get the separate systems that can be deployed individually, but they come up and are used as a whole.

    You can use tags to name docker images. This makes it somewhat easy to chain dockerfile:

    Assuming a directory . with sub-directories for modules module1, …

    docker build -t "module1" module1
    docker build -t "module1" module2

    If this is the sequenced used for building then in module2/Dockerfile you can use

    FROM module1

    Not perfect, because why would module2 need to know ahead of time about module1, but it works.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.