Opstree
Published in

Opstree

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.

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.

{
"version": 2,
"remoteDnsServers": ["nameserver1","nameserver2"],
"envs": [
{
"name": ""
}
],
"activeEnv": "",
"webServerPort": 0,
"dnsServerPort": 0,
"defaultDns": null,
"logLevel": "",
"logFile": "",
"registerContainerNames": null,
"hostMachineHostname": "",
"domain": "",
"dpsNetwork": false,
"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

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 is a end-to-end DevOps consultant company which helps different organization to implement DevOps practices

Recommended from Medium

Dev 1.02 | Sprint 2 [10.15.2020–11.5.2020]

How to Get Out of the Tutorial Hell?

What is :: a (double colon) in ruby?

Insight To Pair Programming

N Queens Problem

DWM Tile Window Manager Keyboard short cut keys Issue

Maintain better range.

Open sourced my live streaming SaaS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ankur

Ankur

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

More from Medium

Database Installation in Linux

Docker & Nginx & Logs

Setup Nexus OSS on Docker as Docker Registry for Learning

Deploy to Kubernetes in 5 minutes with Docker Compose and Okteto Cloud