It would be really nice if we could have network aliases applied to dynamic networks that are created by default in docker if you don't specifically provide a named network. This would allow us to spin up multiple copies of the same set of containers in isolation from each other (if using the -p flag). As an example, given the following config:
services:
moto.local:
image: moto:1.0.0
command: -p 80 -H 0.0.0.0
networks:
test:
aliases:
- email.us-east-1.amazonaws.com
api.app.local:
image: api:composer
networks:
- test
If I want to spin up more than one of these environments using composer, and I want each environment to run in isolation from the other, I would have to do the following:
services:
moto.local:
image: moto:1.0.0
command: -p 80 -H 0.0.0.0
api.app.local:
image: api:composer
and then run
docker-compose up -p <name>
so that each environment has a network based off it's own name. However, I lose the ability to use my aliases that I defined in the first config set. As of now I use "links" instead, however, those are defined on the consuming containers, and need to be defined in many locations through the config files, rather than just a single time on the container that provides the service.
Thanks!
Why do you lose the aliases with -p
? I don't think that should happen.
Well, it's not that I _lose_ the aliases per se, however, I have no way to specify them. The config syntax is:
service:
networks:
some-network:
aliases:
- alias1
- alias3
and "some-network" is going to be dynamically defined based on the value provided to "-p". So I don't have any way to specify the aliases in advance. Am I missing something?
Thanks!
-Dan
Oh yes, you can use default
as the network name, so you can do this:
service:
networks:
default:
aliases: ...
Ah! Thanks, that is exactly what i needed! Did I miss a doc somewhere that mentions that?
Aliases aren't specifically documented, but I believe this is covered by https://docs.docker.com/compose/networking/#configuring-the-default-network
Thanks!
I ran across this thread because I too am trying to get docker-compose to allow communication from a client container to a mysql container, and I too am finding that mysql insists upon using a socket, no matter what I provide as parameters.
I can't explain this, but I have noticed that the problems described above occur if I do this:
dbservice:
...
clientservice:
command: a_script_that_calls_mysql # with -hdbservice
But mysql accepts the host parameter and uses TCP as instructed if I do this
dbservice:
...
clientservice:
command:
- /bin/bash
- -c
-
|
sleep 15
mysql -hdbservice
Hopefully that's a clue for anyone else who wanders by.
Most helpful comment
Oh yes, you can use
default
as the network name, so you can do this: