Dockerfile vs Docker image
Asked Answered
A

2

10

I'm working on creating some docker images to be used for testing on dev machines. I plan to build one for our main app as well as one for each of our external dependencies (postgres, elasticsearch, etc). For the main app, I'm struggling with the decision of writing a Dockerfile or compiling an image to be hosted.

On one hand, a Dockerfile is easy to share and modify over time. On the other hand, I expect that advanced configuration (customizing application property files) will be much easier to do in vim before simply committing an new image.

I understand that I can get to the same result either way, but I'm looking for PROS, CONS, and gotchas with either direction.

As a side note, I plan on wrapping this all together using Fig. My initial impression of this tool has been very positive.

Thanks!

Approximation answered 23/1, 2015 at 18:7 Comment(2)
Same discussion as distributing an application as source code or compiled binaryJackijackie
Interesting way to put it. I hadn't thought of it that way.Approximation
C
13

Using a Dockerfile:

  • You have an 'audit log' that describes how the image is built. For me this is fundamental if it is going to be used in a production pipeline where more people are working and maintainability should be a priority.
  • You can automate the building process of your image, being an easy way of updating the container with system updates, or if it has to take part in a continuous delivery pipeline.
  • It is a cleaner way of create the layers of your container (each Dockerfile command is a different layer)

Changing a container and committing the changes is great for testing purposes and for fast development for a conceptual test. But if you plan to use the result image for some time, I would definitely use Dockerfiles.

Apart from this, if you have to modify a file and doing it using bash tools (awk, sed...) results very tedious, you can add any file you wish from outside during the building process.

Coney answered 23/1, 2015 at 19:59 Comment(1)
I suppose my initial idea that I could make a Dockerfile and simply email that to anyone without context is a bit flawed. Rather than editing config files as RUN commands, I'm starting to see that adding them as volumes is still a nice medium without going the full knee-jerk of committing an image.Approximation
H
12

I totally agree with Javier but you need to understand that one image created with a dockerfile can be different with an image build with the same version of the dockerfile 1 day after.

maybe in your build process you retrieve automatically last updates of an app or the os etc …

And at this time if you need to reproduce a crash or whatever you can’t rely on the dockerfile.

Hypotaxis answered 20/1, 2016 at 11:15 Comment(2)
This helped me a lot. I can't believe I didn't think about this before!Hawserlaid
Dockerfiles need to fully specify the versions of the things they call and include, or you will get the irreproducible behavior described here. If a dockerfile (or a makefile, or any build tool) produces different results for different runs, then it's written wrong. If the build tool is pulling from some form of repository that doesn't let you ensure you get the same thing each time, then the repository is designed wrong.Metallic

© 2022 - 2024 — McMap. All rights reserved.