Closed kedh closed 2 years ago
The title of the issue does not seem to match the problem described, so I'm going to try to address the description rather than multiple docker networks.
It's possible that the IP your myapp.dev
container has is not the same as when your script modified your local /etc/hosts
file. That's because IPs in a docker network are allocated in order on a first-come-first-served basis, so your container will not always get the same IP if other containers are running.
You can check the IP your container currently has using the following command:
docker container inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
<your-container-name-or-id>
More generally I'd recommend looking into DNS based solutions rather than manual or scripted modifications to your local /etc/hosts
file as they're much more resilient to changing IP addresses.
If this doesn't help it would be useful if you could post a small test case including the docker commands you run to create the docker network(s) and containers.
I think there was a misunderstanding. I have updated the original description with more details. Thank you.
Aha, gotcha! Unfortunately I have to start by saying that multiple networks aren't supported by this script. I suspect it's possible with some modifications but I've never had the need to try it.
While I realise this is far from ideal, one solution you may be able to use until support for this is added, (either here, or to docker itself) is to set up your docker network outside of your compose
definition, and then have both apps use the same pre-existing network (see here for how to do that).
I shall leave this issue open as multiple network support is definitely worth having, but I can't commit to a timeline for when that might be possible, sorry 🙁
@kedh as a quick update, one of the folks on the Docker forums also had need of multiple docker network support and so created their own solution based on this repo but more closely mirroring the behavior of Docker for Windows (rather than Docker on Linux as this repo tries to). The setup is a bit more involved as it requires a priviledged container and some manual route creation. I've not had a chance to try it yet, but depending on your needs it may be of interest.
Hello,
I am using this project to create a custom domain connection between a container and my host machine (ex, 'http://myapp.dev' redirects to the corresponding container). I wrote a script that helps my development process by performing the following instructions:
docker-compose up <other options>
docker-for-mac-host-bridge
project'sinstall.sh
script to create connection between my host machine and the container (network name:myapp_net
)/etc/hosts
file accordinglyThis works perfectly fine only when one docker network is being used with tuntap. However, If I want to work on two different projects with two separate docker networks (
myapp_net
andanotherapp_net
), and use the same script to spawn up those projects, both of the projects' custom domain will not work (connection timeout). I tested and checked that both containers were running correctly with two unique network ip addresses, docker networks were set up correctly, and/etc/hosts
file was updated with correct information(ex,172.21.0.3 myapp.dev
and172.18.0.3 anotherApp.dev
). Also, the containers were reachable by localhost port bindings (ex,0.0.0.0:32778->80/tcp
and0.0.0.0:33061->80/tcp
) but not by ip addresses assigned in their networks (ex, 172.21.0.3 and 172.18.0.3) which causes connection timeout error. I assume this problem is causing due to attempts of connecting two networks with only onetuntap
interface (I only have onetuntap
interface on my host machine,tap1
). Is there a way to support two different docker networks at the same time?At this point, If I want to work on a different project, I have to perform
docker-compose down
on current running project and remove its network, and then run the script from above to start the different one.Thank you.