I have two docker containers (container_one and container_two), one is linked to the other container_one >>link>> container_two.
when i run a curl command from within container_one using the address: http://container_two/index.php the curl command executes successfully as expected.
however, i would like to introduce a wildcard subdomain so that i can attach any number of subdomains to container_two (eg: site1.container_two, site2.container_two, *.container_two, etc). Obviously, calling a curl command from container_one: http://site1.container_two/index.php does not work with linking alone.
Does anyone know how this would be possible with a docker run command or perhaps some other way?
Docker also has a linking system that allows you to link multiple containers together and send connection information from one to another. When containers are linked, information about a source container can be sent to a recipient container.
If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.
You can create multiple networks with Docker and add containers to one or more networks. Containers can communicate within networks but not across networks. A container with attachments to multiple networks can connect with all of the containers on all of those networks.
Basically, you cannot do this with just --link
flags, because --link
adds an entry to the /etc/hosts
file to facilitate this inter-container communication, and /etc/hosts
files do not support wildcard entries.
However, you could set up a DNS server on your container_one
, and set up your wildcard host (or subdomain records) on that DNS server to point to your container_two
(and forward all other requests to your actual DNS for all other hostnames), and then specify --dns=127.0.0.1
in your docker run
command for container_one
. This seems a bit hacky, but what happens is that container_one
will then use 127.0.0.1
(localhost) when it encounters a hostname it does not recognize in /etc/hosts
, and the DNS on container_one
will point to container_two
for subdomains (and all other requests forwarding to your external DNS infrastructure).
You can find more information about this in the documentation. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With