Docker Community Forums

Share and learn in the Docker community.

Newbie - how to maintain docker image with code in GIT repository?

docker

(Gerwim) #1

So, I’ve just started using docker and it’s awesome!

However, like many ‘newbs’ do, they run into stuff. I’m, for example, running into the fact that I don’t know how to manage my files. I mean, I have a single dockerfile with a FROM and ENTRYPOINT line, easy, right?

Yes, however I want to put the dockerfile in git (which is no issue either), but how do I store the docker image? What’s the best way to do this? Do people just use docker pull when they start on a specific branch and is it just naming conventions? Like docker push MyImage:gitrevision or do people actually store their image in GIT?


(David Maze) #2

You don’t really need to; you can always docker build from the Dockerfile you’ve written and checked in. If you’re using Docker Compose, you can check in the docker-compose.yml file too, which has enough details on how to build and run the image that (for something small) just the source code is almost definitely “good enough”.

If you do want to save the image somewhere, you need a Docker Hub account or to run a private registry, and then you can docker push the image to the registry. That would let other people docker pull it and use it directly, without the build step.

The home-grown build system we use pushes images with both a versioned tag and latest, but it doesn’t really understand non-default branches.

You definitely should not try to store images in git. You can’t directly access the image contents. You could docker save, but it’s kind of slow and produces a very large binary file, which will make your git repository huge, forever.

If you’re talking about saving the images somewhere, the Dockerfile should almost certainly have a COPY line to add your application, so the image can be self-contained.


(Gerwim) #3

Hi David,

Thanks for your comprehensive reply.

I think I know why I’m trying to store the image file withit GIT: it’s because I don’t really use the compose and/or Dockerfile contents (apart from ENTRYPOINT to start services): it’s because I modify the actual image and use docker commit to store the changes.

If I was using proper Dockerfile, which would change the content of the image by using COPY, RUN etc. instead of what I do, using bash to change contents of files, installing packages the issue would not have risen.

Seems like I’ve been doing Docker wrong for the last couple of days :slight_smile: