Why docker container name has an random number at the end?

docker-compose container name
docker container naming convention
docker-compose build
docker-compose command
docker-compose template
docker-compose volumes
docker-compose container name scale
docker-compose multiple containers

I have a docker-compose.yml file as below (a piece of it):

version: '3.5'
    build: ./fmk
      - "2020:2020"
      - "2025:2025"
      - "4999:4999"
      - ${FOLDER_ENV}/workspace/logs/framework:/var/log/gcti
      - ${FOLDER_ENV}/..:/usr/local/genesys/gsg_qaart

what I got is:

vagrant@docker:/repos/gsg_qaart/docker$ docker-compose ps
]              Name                             Command               State                                             
callback_framework_1_df361f67842c   /bootstrap.sh                    Up>2020/tcp,>2025/tcp,>4999/tcp, 5432/tcp

As you can see the name is weird, it supposes to be "callback_framwork_1", why there is a random number at the end?

BTW, I'm using:

vagrant@docker:/repos/gsg_qaart/docker$ docker -v
Docker version 18.09.0, build 4d60db4
vagrant@docker:/repos/gsg_qaart/docker$ docker-compose -v
docker-compose version 1.23.1, build b02f1306



This change is reverted in v1.23.2

So there is an important change in the compose v1.23, https://github.com/docker/compose/releases/tag/1.23.0

The default naming scheme for containers created by Compose in this version has changed from project_service_index to project_service_index_slug, where slug is a randomly-generated hexadecimal string. Please make sure to update scripts relying on the old naming scheme accordingly before upgrading.

Therefore if you want to have a deterministic container name, use

        container_name: framework

Proposal: Stop using sequential container numbers · Issue #1516 , Sequential container numbers (myapp_web_1, myapp_web_2) are problematic. can't use docker-compose run in parallel #1708 I had to use cat /proc/sys/​kernel/random/uuid instead of uuidgen since that wasn't available  Stack Overflow Public questions and answers; Why docker container name has an random number at the end after creating docker sevice.

I cannot hardcode container name and I want to be able to run from any directory. So I ended up grepping part of the name:

docker exec -it $(docker ps --format='{{.Names}}' | grep server) bash

Docker Cookbook: Over 100 practical and insightful recipes to , Over 100 practical and insightful recipes to build distributed applications with The Docker Engine autogenerates the name of the host end veth pair by In this example, e8b40b8 is the random number generated by the Docker Engine. The Ubuntu Linux distribution does not usually carry the brctl tool, so we have to​  Why docker container name has an random number at the end? 5 1

Note, the other answers/troubleshooting are valid/correct, but I'd like to give some food for thought on working with docker-compose, despite how docker-compose reverted the slug change. There is a good practice that can be highlighted in in making use of docker-compose services.

My personal thoughts are docker-compose was attempting to pursue a shift in how their tool was being used. I read somethings on github that hinted at that, but that's my opinion after reading some of their developers feedback, specifically from the following github issue on the slugs.

Making use of docker-compose's internal service mechanisms

I'm attempting to generalize, since the following examples may not be fully applicable to your setup, but they should be helpful none the less. Since you're already using docker-compose, there is a benefit to using service discovery provided via docker networks and docker-compose over hard-coding access via container names.

When using docker-compose, services are created that are composed of 1..* containers. In your example, the service framework is created with 1 container callback_framework_1_df361f67842c.

Accessing a service from within another docker container/code in a docker container

A service can be used for DNS/networking instead of container names, that is everywhere <protocol>://<host>:<port>/<endpoint> where the container name was used as the <host>, the service name can also be used as the <host> (eg executing ping inside of another container on the docker network):

ping <service>
ping framework


ping <container-name>
ping callback_framework_1_df361f67842c

Both the above pings work. Docker takes care of the networking to the appropriate container, farther when there are multiple containers that compose a service, it takes care of load balancing requests to the containers.

Accessing your containers via service from the host machine, ie running docker commands from scripts

Addressing if you have scripts executing from the host machine, you can also make use of docker-compose instead of docker commands as well:

docker-compose exec <service> sh
docker-compose exec framework sh


docker exec -it <container-name> sh
docker exec -it callback_framework_1_df361f67842c sh

docker-exec defaults to the first container, but when there are multiple containers that compose a docker service, a target container can be addressed using the --index=<index> flag. See docker-compose exec documentation for more details.

Docker 0.6.5: Name your containers, link them, and more, Don't be fooled by the version number: this is a significant release! When you link one container to another you will have to provide the name and alias of the child that you want to link to via -link See the end of this section for details. Before I was taking care of it in the Dockerfile using a random port:. Docker random container naming number=1) 19.144520926987752. Docker version 19.03.5, build 633a0ea838 // Ubuntu 18.04 image w/ Python 3.8 installed from Canonical

Docker run reference, As a result, the process will not terminate on SIGINT or SIGTERM unless it is coded a container name with the --name option, then the daemon generates a random If you specify a name , you can use it when referencing the container within a Debug the redis container by running another container that has strace in it:. To help the humans, Docker also supplies containers with a randomly-generated name from two words, joined by an underscore, e.g. evil_ptolemy. This can make it easier to tell one container from another, but the random names don’t give any more insight into the container function than the UUID.

docker stats, The PIDS column contains the number of processes and kernel threads created docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET 0B 1 4bda148efbc0 random.1.vnc8on831idyr42slu578u3cr 0.00% 1.672MiB  Note that if no name is specified, by default, the the Docker daemon assigns containers a UUID long identifier; it generates a random string as a name. How to Name a Docker Container You can assign memorable names to your docker containers when you run them, using the --name flag as follows.

docker create, The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. Number of CPUs --domainname, Container NIS domain name --publish-all , -P, Publish all exposed ports to random ports --stop-signal, SIGTERM, Signal to stop a container. Docker default container names When you create a new Docker container and don’t give a custom name (by passing --name <name> on the CLI) Docker generates a name for you. For all commands you later run that interact with the container you can either use its hash ID or its name.

  • what's the output of docker ps?
  • e743b462e56c gme/fmk:callback "/bootstrap.sh" 2 minutes ago Up 2 minutes>2020/tcp,>2025/tcp,>4999/tcp, 5432/tcp callback_framework_1_2d34e5dc1703
  • I am also getting this after I just updated to the latest docker version. It broke my scripts because I can no longer count on the container name being constant
  • I guess this broke LOADS of scripts (including the ones of my team, of course). No wonder they rolled it back in less than a month.