Antirreni91
Antirreni91

Reputation: 385

Docker networks do not have consistent name

Depending on the host where I'm running Docker-compose, I get different network naming. For instance:

This is my docker-compose file:

./my-project-folder/docker-compose.yml

version: '3'

services:

  search:
    build: docker/server
    container_name: server
    ports:
      - 9200:9200

I have a project called my-project-folder and the network is called:

my-project-folder_default

But sometimes I get this network name:

myprojectfolder_default

Is there a way to have consistent network names?

Upvotes: 0

Views: 129

Answers (2)

David Maze
David Maze

Reputation: 159865

docker-compose -p or the COMPOSE_PROJECT_NAME environment variable will manually set that prefix, rather than letting Compose decide for itself based on the directory name. This would still let you have multiple copies of the stack running on the same system if you needed to (forcing container_name and the network name would cause multiple deployments to conflict).

Upvotes: 1

juanlumn
juanlumn

Reputation: 7135

Have you tried defining an entry under networks?

version: '3'

services:

  search:
    build: docker/server
    container_name: server
    ports:
      - 9200:9200
    networks:
      - your-network-name

networks:
  your-network-name: ...

There is some interesting information in the Compose File Reference V3 Documentation

According to the previous doc:

version: '3.5'

services:
  search:
    build: docker/server
    container_name: server
    ports:
      - 9200:9200
    networks:
      - your-network-name

networks:
  your-network-name:
   name: your-global-net

Please note that you will need at least Docker Engine 17.06.0 for this to work and you need to use the latest version of docker-compose yml.

To check that you can simply type:

docker version

Upvotes: 0

Related Questions