Building a new docker image with the same name as an existing ones

Images in Docker don't have a name, they have tags.

A tag is a reference to an image. Multiple tags may refer to the same image.

If you reassign a tag that is already used, then the original image will lose the tag, but will continue to exist (it will still be accessible by its image ID, and other tags might refer to it).


An easy way to clean up unused images and save disc space is to alias a cleanup command in your terminal by adding it to ~/.bashrc or ~/.bash_profile:

alias docker_rmi_dangling="docker rmi $(docker images -qa -f 'dangling=true')"

Then run docker_rmi_dangling in your shell.

(Inspiration from this comment)


You can use versions with your tags e/g/:

docker build -t <USER>/<CONTAINER>:<VERSION>   
docker build -t maluuba/haproxy:2
docker build -t maluuba/haproxy:latest  #Default behavior when you don't use version
docker build -t maluuba/haproxy:old

Tags:

Docker