How to create named and latest tag in Docker?

Supposed I have an image that I want to tag as 0.10.24 (in my case it’s an image containing Node.js 0.10.24). I built that image using a Dockerfile and executing docker build and by providing a tag using the -t parameter.

I expect that one day I will have additional versions of that image, so I will rerun the process, just with another tag name.

  • Rubygems update fails on strange ruby versions
  • Where can I configure the start user UID for Docker containers?
  • docker-compose : Unsupported config option for services service: 'web'
  • Pycharm not showing all files from django external library
  • How restart a stopped docker container
  • Error after importing JDL using jhipster with docker
  • So far, so good. This works great and fine and all is well.

    But, and this is where problems start, I also want to always have the newest image tagged ad latest additionally. So I guess I need to give two names to the very same image.

    How do I do this? Do I really need to re-run docker build on the exact same version again, but this time use another tag, is is there a better option?

  • Unable to set up Docker UCP cluster
  • How to prevent docker containers from consuming all CPU?
  • Why install docker on ubuntu should be `sudo apt-get install`?
  • Unable to connect a dockerised keystone container with a dockerised mongo container
  • error: couldn't read version from server: Get http://localhost:8080/api: dial tcp connection refused
  • Debugging linked docker containers when using docker-compose
  • 6 Solutions collect form web for “How to create named and latest tag in Docker?”

    You can have multiple tags when building the image:

    $ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .


    Once you have your image, you can use

    $ docker tag <image> <newName>/<repoName>:<tagName>

    1. Build and tag the image with creack/node:latest

    $ ID=$(docker build -q -t creack/node .)

    2. Add a new tag

    $ docker tag $ID creack/node:0.10.24

    3. You can use this and skip the -t part from build

    $ docker tag $ID creack/node:latest

    Here is my bash script

    docker build -t ${IMAGE}:${VERSION} .
    docker tag ${IMAGE}:${VERSION} ${IMAGE}:latest

    You can then remove untagged images if you rebuilt the same version with

    docker rmi $(docker images | grep "^<none>" | awk "{print $3}")



    docker rmi $(docker images | grep "^<none>" | tr -s " " | cut -d' ' -f3 | tr '\n' ' ')


    Clean up commands: as of docker 1.13 introduces clean-up commands. To remove all unused containers, images, networks and volumes:

    docker system prune

    or individually:

    docker container prune

    docker image prune

    docker network prune

    docker volume prune

    ID=$(docker build -t creack/node .) doesn’t work for me since ID will contain the output from the build.

    SO I’m using this small BASH script:

    set -o pipefail
    IMAGE=...your image name...
    VERSION=...the version...
    docker build -t ${IMAGE}:${VERSION} . | tee build.log || exit 1
    ID=$(tail -1 build.log | awk '{print $3;}')
    docker tag $ID ${IMAGE}:latest
    docker images | grep ${IMAGE}
    docker run --rm ${IMAGE}:latest /opt/java7/bin/java -version

    Variation of Aaron’s answer.
    Using sed without temporary files

    ID=$(docker build  -t ${IMAGE}  .  | tail -1 | sed 's/.*Successfully built \(.*\)$/\1/')
    docker tag ${ID} ${IMAGE}:${VERSION}
    docker tag -f ${ID} ${IMAGE}:latest

    Just grep the ID from docker images:

    docker build -t creack/node:latest .
    ID="$(docker images | grep 'creak/node' | head -n 1 | awk '{print $3}')"
    docker tag "$ID" creack/node:0.10.24
    docker tag "$ID" creack/node:latest

    Needs no temporary file and gives full build output. You still can redirect it to /dev/null or a log file.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.