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?
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.
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
Hi Gerwim, I hope you already did what you wanted, as this is old post, Can you share that how did you save the your own created image and pushed it to GIT and pull it when you needed from there?
Yes! I solved it indeed. Basically, you’ll need to host your image somewhere. I use GitLab (self hosted, but I think the SaaS offering works too) to build my images. My repositories contain a .gitlab-ci.yml file which build the image and then upload it to GitLab’s container registry.
If you don’t mind sharing the images (without paying) to the outside worlds, you can also use Docker Hub to host them.
So the gist:
Build the Dockerfile (albeit a CI runner, Docker Hub auto builds or by hand)