Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify network name in docker-compose file #3736

Closed
ivstas opened this issue Jul 15, 2016 · 26 comments
Closed

Specify network name in docker-compose file #3736

ivstas opened this issue Jul 15, 2016 · 26 comments
Milestone

Comments

@ivstas
Copy link

ivstas commented Jul 15, 2016

Is it possible to provide ability to set a name for network in docker-compose file?

Like this:

networks:
  custom_network:
    name: custom_network_name

Thanks in advance!

@vingrad
Copy link

vingrad commented Jul 16, 2016

for overlay network:
network_mode: custom_network_name

@ivstas
Copy link
Author

ivstas commented Jul 17, 2016

@vingrad does it work for overlay network only?

@vingrad
Copy link

vingrad commented Jul 17, 2016

no, but for other networks you need to use othe syntax: https://docs.docker.com/compose/compose-file/#/networks

@ivstas
Copy link
Author

ivstas commented Jul 17, 2016

@vingrad resulting network name is project name + _ + network name in compose file. Is it possible to set resulting network name?

@aanand
Copy link

aanand commented Jul 20, 2016

@ivstas If you want full control over the network name, create it yourself and then reference it as external in your Compose file:

networks:
  custom_network:
    external:
      name: custom_network_name

@ivstas
Copy link
Author

ivstas commented Jul 20, 2016

@aanand I know about this opportunity. Also, the same could be told about container names, but we do have an opportunity to set container name in compose file, right?

@aanand
Copy link

aanand commented Jul 21, 2016

Yes, but I don't think adding that was a good idea.

@jroitgrund
Copy link

@aanand Why is that?

Aliases work fine for most cases but a Kerberos client, for example, uses reverse DNS Lookup to figure out the canonical hostname of a service, and reverse DNS lookup always yields <container_name>.<network_name>, so being able to hardcode both would be really useful.

@andkirby
Copy link

Yeah, it will be quite useful.
You really could use particular names in commands like this:

$ docker inspect --format "{{.NetworkSettings.Networks.my___name.IPAddress}}" my-nginx

@tarach
Copy link

tarach commented Feb 12, 2017

I have two projects one is started using docker run ( with systemd ) and other one is started using docker-compose How am I suppose to put them both on the same network?
With run I only had to use --net=bridge but with docker-compose its a whole another story. Nothing I try works... :/

@ugommirikwe
Copy link

@tarach I think this answers your question: https://docs.docker.com/compose/networking/#using-a-pre-existing-network

@tarach
Copy link

tarach commented Feb 13, 2017

Yes, I was thinking more of a way of setting the default network for docker-compose.
The fact that d run uses bridge network by default and compose creates their own is a little bit confusing.

Since I was unable to set bridge network in docker-compose because it apparently is for user defined networks only I've obviously created a network and assigned it to both d run and d-compose.

@denzel-morris
Copy link

I think allowing a network to be named, like container_name works today, is valuable. I also think this interacts with #2075 in that you should be able to specify a create_if_missing property that will allow a network to be shared between multiple services, defined in separate compose files, without resulting in a network name conflict.

Our workaround for solving this use case at my company is to wrap docker-compose in a shell script. Essentially:

create_docker_network_if_exists $NETWORK
docker-compose "$@"

Which is invoked with: NETWORK=custom-net ./scripts/docker-compose.sh up [...]. Obviously this is less than ideal and we'd enjoy a more elegant solution.

If any core devs are able to provide me with context on what should be taken into consideration re: implementing a solution, then I'd be more than happy to submit a PR.

@approxit
Copy link

approxit commented Nov 6, 2017

And this is a another example of small features request that are demanded by users but "implicitly wontfix" because it seems not valuable for devs... 😕

For me docker-compose.yml is a STATIC way to declare FULL deploy configuration. My case requires specific network names to work properly. I want to write everything into .yml file, but docker-compose is forcing prefix for my networks. I need to make workarounds with totally separate flow to prepare networks manually, mark networks as external in .yml file, and finally whole application.

docker-compose should take care of everything, but it's not doing that...

Adding configurable network name is absolutely the same business-case that container_name - it's have drawbacks that you need to be aware of. Only the notation of network name could be problematic - but it should not be a blocker.

@Hronom
Copy link

Hronom commented Jan 2, 2018

What the progress on this?

Also need this feature, it's like container_name.

Here is the case: each application can consist of several microservices, so each application can have own docker-compose file, but all applications lives in one network.

@shin-
Copy link

shin- commented Jan 3, 2018

Fixed by #5448

@shin- shin- closed this as completed Jan 3, 2018
@shin- shin- added this to the 1.18.0 milestone Jan 3, 2018
@roboto-cloud
Copy link

@shin-ok but how use it?

@ctodea
Copy link

ctodea commented Feb 13, 2018

@roboto-cloud

networks:
  foo:
    name: bar

Make sure that you're using version: '3.5' or higher

@nouchka
Copy link

nouchka commented Mar 26, 2018

Thx for the feature
Seems to work only with docker-compose, not docker stack deploy

@Ali-Kiyan
Copy link

@ivstas If you want full control over the network name, create it yourself and then reference it as external in your Compose file:

networks:
  custom_network:
    external:
      name: custom_network_name

I am using network alias for this container is there any way to provide that in here?

adaszko added a commit to rchain/perf-harness that referenced this issue Feb 14, 2019
Specifying exact docker network name is not available in the
docker-compose version present on google cloud machines.  This can and
should be replaced with a docker-compose directive once file format 3.5
is usable on the instances [1].

[1] docker/compose#3736
adaszko added a commit to rchain/perf-harness that referenced this issue Feb 14, 2019
Specifying exact docker network name is not available in the
docker-compose version present on google cloud machines.  This can and
should be replaced with a docker-compose directive once file format 3.5
is usable on the instances [1].

[1] docker/compose#3736
adaszko added a commit to rchain/perf-harness that referenced this issue Feb 14, 2019
Specifying exact docker network name is not available in the
docker-compose version present on google cloud machines.  This can and
should be replaced with a docker-compose directive once file format 3.5
is usable on the instances [1].

[1] docker/compose#3736
adaszko added a commit to rchain/perf-harness that referenced this issue Feb 14, 2019
Specifying exact docker network name is not available in the
docker-compose version present on google cloud machines.  This can and
should be replaced with a docker-compose directive once file format 3.5
is usable on the instances [1].

[1] docker/compose#3736
@albertdick
Copy link

@roboto-cloud

networks:
  foo:
    name: bar

Make sure that you're using version: '3.5' or higher

Best answer.

@onzag
Copy link

onzag commented May 19, 2020

I use version 3.5 and I get that property name was unexpected.

ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.foo value Additional properties are not allowed ('name' was unexpected)

@juan-montilla
Copy link

juan-montilla commented Jun 14, 2020

I use 3.5 version as well and i get the same error as @onzag

ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.khala value Additional properties are not allowed ('name' was unexpected)
networks:
  khala:
    name: khala
    driver: bridge

@fishtenors
Copy link

@juan-montilla Can you post your full compose file and the docker version? I just tested with Docker version 19.03.8 and a compose file version of 3.8 on macOS and it worked.

@juan-montilla
Copy link

@fishtenors sure!

---
version: "3.5"

networks:
  khala:
    name: khala
    driver: bridge

volumes:
  nginx:
    driver: local
    
services:
  nginx:
    image: nginx:alpine
    build: ./nginx
    volumes:
      - ~/federation/www:/var/www
    ports:
      - ${NGINX_PORT}:80
      - ${NGINX_SSL_PORT}:443
    environment:
      - NGINX_HOST=${NGINX_HOST}
    networks:
      - khala
Docker version 19.03.11, build 42e35e61f3

I do not know if relevant.. but i am using Ubuntu 18.04

@fishtenors
Copy link

@juan-montilla Your compose file worked for me. Since you're using Docker 19.03+, you could try bumping the version up to 3.8. But that's just taking a stab in the dark. What version of compose are you running (docker-compose --version)? Maybe try upgrading compose to the latest?

moonrailgun added a commit to msgbyte/tailchat that referenced this issue Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests