DEV Community

Danyson
Danyson

Posted on • Edited on

How to version Docker Images?

If we use git for version management of our code base, similarly we can use Docker as our version management tool for applications.

Lets imagine, we have an application called "Icecream".

We are going to store our "Icecream" application on a repository named "Fridge" so, lets get the root access by executing the command

sudo -i
Enter fullscreen mode Exit fullscreen mode
  • First we need to login to our repository called "Fridge"
docker login Fridge
Enter fullscreen mode Exit fullscreen mode
  • Now pull the "Icecream" image from our "Fridge"
docker pull Fridge/Icecream:plain

// syntax: docker pull repo_name/Image_name:version_tag
Enter fullscreen mode Exit fullscreen mode
  • If we don't have a docker image named "Icecream", on our "Fridge" repository, then lets build one
docker build -t Icecream:plain
// this command is executed from the working directory where our docker file is placed
Enter fullscreen mode Exit fullscreen mode
  • Now as we have our "Icecream:plain, lets modify it to "Icecream:vanilla" and "Icecream:chocolate".

  • For that we need to run our Icecream:plain in to a container

docker run -it Icecream:plain bash
Enter fullscreen mode Exit fullscreen mode
  • Add the code for vanilla in our container and do
docker ps
Enter fullscreen mode Exit fullscreen mode
  • copy the container id of the running container and commit
docker commit <container_id> Icecream:vanilla
Enter fullscreen mode Exit fullscreen mode
  • Now run our "Icecream:plain" in to a container again
docker run -it Icecream:plain bash
Enter fullscreen mode Exit fullscreen mode
  • Add the code for chocolate in our container and do
docker ps
Enter fullscreen mode Exit fullscreen mode
  • copy the container id of the running container and commit
docker commit <container_id> Icecream:chocolate
Enter fullscreen mode Exit fullscreen mode
  • Now push the changes to your "Fridge" repository
docker push Icecream:vanilla
docker push Icecream:chocolate
Enter fullscreen mode Exit fullscreen mode

Explore us more on : Doge Algo 🐶

Support Us on Buy Me a Coffee

Top comments (0)