Resolve Docker Container From Host
Docker is the most powerful tool to do the development and run the application. Docker helps us to resolve multiple problems by providing an isolated environment but have own challenges. Like accessing an application running inside a container.
This blog will help you to access your application from the container without doing the port mapping. You have just passed the container hostname and port to access the application from the host machine.
To achieve this we will be using a dns-proxy-server. Please use the following link to download the utility.
GitHub - mageddo/dns-proxy-server: Solve your DNS hosts from your docker containers, then from your…
DPS is a end user(developers, Server Administrators) DNS server tool to develop systems with docker solving docker…
Let’s start the dns-proxy-server using docker in the Linux instance.
docker run --rm --hostname dns.mageddo --name dns-proxy-server -p 5380:5380 -v /opt/dns-proxy-server/conf:/app/conf -v /var/run/docker.sock:/var/run/docker.sock -v /etc/resolv.conf:/etc/resolv.conf -d defreitas/dns-proxy-server
Here we are running DPS in a docker container and mount /opt/dns-proxy-server/conf for the configuration file. This path contains the config.json file.
Following is the configuration file(config.json) to set up the dns-proxy-server in the Linux instance. As if we will not using the below configuration maybe you face some issue while resolving the public IP’s or installing/access the internet from the container and host machine.
"dpsNetworkAutoConnect": true #this will connect dps with all the docker network running in hosts
Launch DPS Container
Let’s launch a two mysql container using the same port and access them from the hostname
Access the mysql container using hostname for host withing port mapping
For Docker-compose define the hostname in the docker-compose.YAML and use DPS labels. For reference please use the below link