Resolve Docker Container From Host

Ankur
Ankur
Sep 4 · 3 min read

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.

Let’s start the dns-proxy-server using docker in the Linux instance.

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.

Launch DPS Container

Let’s launch a two mysql container using the same port and access them from the hostname

Launch mysql container

Access the mysql container using hostname for host withing port mapping

Access mysql containers

For Docker-compose define the hostname in the docker-compose.YAML and use DPS labels. For reference please use the below link

Opstree

Opstree is an end-to-end DevOps consultant company

Opstree

Opstree is a end-to-end DevOps consultant company which helps different organization to implement DevOps practices

Ankur

Written by

Ankur

DevOps Engineer with 10+ years of experience in the IT Industry. In-depth experience in building highly complex, scalable, secure and distributed systems.

Opstree

Opstree is a end-to-end DevOps consultant company which helps different organization to implement DevOps practices