Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - Restrictions regarding naming container

Tags:

docker


I have questions regarding restrictions about naming containers. I search online and saw different issue and answers.

  1. what is the maximum characters number in naming container?
  2. which special characters are not allowed in docker container name? (e.g. '*', '$', ',', '_' ...)
like image 476
Dror Brook Avatar asked Mar 07 '17 07:03

Dror Brook


People also ask

Do docker container names have to be unique?

Since container names must be unique, you cannot use deliberate naming and scale a service beyond one container.

Can you rename a docker container?

To rename docker container, use the rename sub-command as shown, in the following example, we renaming the container discourse_app to a new name disc_app. After renaming a containers, confirm that it is now using the new name.

What happens if you dont name a docker container?

You can name your own containers with --name when you use docker run . If you do not provide a name, Docker will generate a random one like the one you have.

Can I rename a container?

A container name is given automatically when you create a container if you are not using the "--name" option. Sometimes you want to change the name of a Docker container. This can be done using the "docker container rename" command. As you can see, changing the name of a Docker container is an easy task.


2 Answers

The characters allowed to represent a container name is represented by the regex : src code

// RestrictedNameChars collects the characters allowed to represent a name, normally used to validate container and volume names. const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]` 

see #3138

And only the images name has a limited size of 30 chars.

like image 88
NotBad4U Avatar answered Sep 29 '22 09:09

NotBad4U


Container names must start with an alphanumeric character and can then use _ . or - in addition to alphanumeric. [a-zA-Z0-9][a-zA-Z0-9_.-]+

I'm not sure there is a hard limit set for the length of a container name. You might run into some HTTP URL limits at some point as the name ends up in the path for a number of API calls.

like image 20
Matt Avatar answered Sep 29 '22 11:09

Matt