Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to keep Dockerfile's in a project?

Tags:

docker

jenkins

I am gaining knowledge about Docker and I have the following questions

  • Where are Dockerfile's kept in a project?
    • Are they kept together with the source?
    • Are they kept outside of the source? Do you have an own Git repository just for the Dockerfile?

If the CI server should create a new image for each build and run that on the test server, do you keep the previous image? I mean, do you tag the previous image or do you remove the previous image before creating the new one?

I am a Java EE developer so I use Maven, Jenkins etc if that matter.

like image 291
LuckyLuke Avatar asked Dec 09 '14 20:12

LuckyLuke


People also ask

Where should I put Dockerfiles in project?

I'd recommend keeping the Dockerfile with the source as you would a makefile. The build context issue means most Dockerfiles are kept at or near the top-level of the project. You can get around this by using scripts or build tooling to copy Dockerfiles or source folders about, but it gets a bit painful.

Where are Dockerfiles kept?

The docker images, they are stored inside the docker directory: /var/lib/docker/ images are stored there.

Can you have multiple Dockerfiles in a project?

As Kingsley Uchnor said, you can have multiple Dockerfile , one per directory, which represent something you want to build.

How do I have multiple Dockerfiles?

Let's say we have two Dockerfiles, one for building the backend and another for building the frontend. We can name them appropriately and invoke the build command two times, each time passing the name of one of the Dockerfiles: $ docker build -f Dockerfile.


1 Answers

The only restriction on where a Dockerfile is kept is that any files you ADD to your image must be beneath the Dockerfile in the file system. I normally see them at the top level of projects, though I have a repo that combines a bunch of small images where I have something like

top/   project1/     Dockerfile     project1_files   project2/     Dockerfile     project2_files   

The Jenkins docker plugin can point to an arbitrary directory with a Dockerfile, so that's easy. As for CI, the most common strategy I've seen is to tag each image built with CI as 'latest'. This is the default if you don't add a tag to a build. Then releases get their own tags. Thus, if you just run an image with no arguments you get the last image built by CI, but if you want a particular release it's easy to say so.

like image 96
seanmcl Avatar answered Sep 23 '22 16:09

seanmcl