Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tag a docker container?

Tags:

docker

I'm creating an app when I have several kind of containers, and I want to know if docker has some way of tagging containers (example: database, data-only ...).

Note: This answer is about giving names to containers instead of tags. I'm asking to giving arbitrary tags to containers, not images

like image 904
IAmJulianAcosta Avatar asked Jan 25 '16 19:01

IAmJulianAcosta


People also ask

How do you tag containers in docker?

Docker tags are just an alias for an image ID. The tag's name must be an ASCII character string and may include lowercase and uppercase letters, digits, underscores, periods, and dashes. In addition, the tag names must not begin with a period or a dash, and they can only contain 128 characters.

What is tagging in docker?

Docker tags are mutable named references to Docker images, much like branch refs in Git. They make it easy to pull and run images, and for image authors to roll out updates automatically. For example, to pull the latest Debian GNU/Linux image for the buster release: $ docker pull debian:buster.

How do I tag a docker image as latest?

Latest is Just a Tag It's just the tag which is applied to an image by default which does not have a tag. Those two commands will both result in a new image being created and tagged as :latest: # those two are the same: $ docker build -t company/image_name . $ docker build -t company/image_name:latest .


1 Answers

I think you may be confusing some Docker terminology. Here's a brief list of similar-yet-confusing terms

  • Repository -- a name for a set of images such as 'nginx'
  • Image -- one binary image such with an id such as 407195ab8b07
  • Tag -- a user-defined name for 407195ab8b07 such as 'nginx:1.9.9'
  • Container -- a runnable process the executes the image
  • Label -- a user-defined name/value pair for an image or container

An image can have many tags and labels -- but these are set AT BUILD TIME

Think of an image as a CD or DVD disk for your Xbox -- its a bunch of binary information.

Many containers can be run for an image -- each container runs in its own virtual process and has its own file system, environment.

Think of the container as a Video Game playing on your Xbox -- it's moving and "running" -- a container "runs" an image. So to create the image you say docker run and give it the name of the image to run

docker run nginx:1.9.9

Containers can be named when they are created

docker run --name MyNginx nginx:1.9.9

The container name can be used to stop the container:

docker stop MyNginx

Containers can also have labels added at start-time

docker run --label "foo=BAR" nginx:1.9.9 

Hope this helps

like image 127
Mark Riggins Avatar answered Oct 06 '22 12:10

Mark Riggins