Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

version: '3.5'
services:
    framework:
    image: ${DOCKER_REGISTRY}/gme/fmk:${COMPOSE_PROJECT_NAME}
    build: ./fmk
    ports:
      - "2020:2020"
      - "2025:2025"
      - "4999:4999"
    volumes:
      - ${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                                             
Ports
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
callback_framework_1_df361f67842c   /bootstrap.sh                    Up      0.0.0.0:2020->2020/tcp, 0.0.0.0:2025->2025/tcp, 0.0.0.0:4999->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

Thanks.

like image 454
Michael.X Avatar asked Nov 15 '18 19:11

Michael.X


2 Answers

EDIT.

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

services:
    framework:
        container_name: framework
like image 193
Siyu Avatar answered Nov 15 '22 05:11

Siyu


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
like image 26
simno Avatar answered Nov 15 '22 03:11

simno