When I run the following docker-compose file, the containers are able to connect to each other by using their hostnames as mentioned in the docker-compose file. So container
escher can connect to container
boqs by doing
http://boqs. I think this is because docker changes the internal host files, right? Now my question is: is it possible to do this also for a normal
docker run command so that the host can connect to it by using this name??
So what I want:
- start a container
- connect to it from the host machine by doing: http://boqs (on the same way docker-compose makes this work)
use --name with the first run command and --link with the second
hope that helps
Unfortunately that does not work. I want to run a container and give it a --name, f.e. “redis”. Then I want to connect to that container from the host itself, by connecting to the hostname provided in the --name command.
on the default bridge network there’s no name resolution, to have the same behavior as provided by docker-compose, you must create a network and connect your containers on this network
docker network create mynetwork
docker run -d -p 8060:8060 --name bogs --network mynetwork boqs
docker run -d -p 8080:8080 --name escher --network -e ENV=dev mynetwork escher
you should then access to the boqs container from escher
Thanks; but this is also not what I want, because you’re talking about linking two running containers.
I just want to connect on the host machine to a container (running on that host machine) by connecting to the “name” I used while running the container.