Skip to main content

How to assign static public IP to the docker container  


In this post, we will create a docker container and configure the static public IP so it will be reachable from outside. Here we will use the Linux  MAC VLANs and Virtual Ethernets.

Prerequisites:  
  • Ubuntu host up and running.
  • Public IP should be configured.
  • Docker should be installed.
Skip to end of metadata

PULL UBUNTU DOCKER IMAGE

docker pull  ubuntu:14.04.5
It will download the Ubuntu docker image.


Create a container
docker run -ti --name container-1  --net=none --privileged=true ubuntu:14.04.5 bash
This will create a docker container, now we will configure the static public ip to the container.

ASSIGNING AN IP FOR A CONTAINER

Here I am assuming that host machine is having interface "eth0" with public IP configured. Name of the container is container-1. The below steps needs to be performed on the docker host.
  • Create a virtual interface

    $ ip link add name veth0 link eth0 type macvlan mode bridge
     New virtual interface "veth0" will be created.

  • Get the process id for the salt master container

    $ docker inspect -f '{{.State.Pid}}' container-1
  • $ mkdir -p /var/run/netns

    $ ln -s /proc/<processid>/ns/net /var/run/netns/<processid>

  • Assign the virtual interface to container-1

    $ ip link set veth0 netns <processid> name eth0
Here a new interface eth0 will be created inside the container.

Note: If your ubuntu host machine is running in the EXS then verify the below network setting in the ESX. 
  • Promiscuous Mode , MAC Address Changes and Forged Transmits should be accepted mode.




If any one of them is not set to accept then change it in the ESX network setting (Host -> Configuration ->Networking->Properties->Edit)

  • Here I will use the dhclient to get the public static IP. If you are not having DHCP server configured then you can manually assign the IP to the interface.

    $ docker exec -it container-1 dhclient -v eth0


Now you have successfully configured the static public IP to the docker container.

Here we have used the concept of MAC VLANs and Virtual Ethernets so whenever you will shutdown/stop the container that IP will be lost. It means whenever you will start the container you have to configure the IP again.

If you have used the dhclient to get the static public IP for the container then getting the same IP again is little bit tricky. Check out this guide to get the same IP from DHCP server to the docker container.

Comments

Popular posts from this blog

Running Salt Minion In Docker Container From Scratch  In this post, we will install salt minion in docker container and configure the public IP so it will be reachable from outside. Prerequisites:     Ubuntu host up and running. Public IP should be configured. Docker should be installed. Skip to end of metadata Go to start of metadat PULL UBUNTU DOCKER IMAGE $  docker pull    ubuntu:14.04.5 It will download the Ubuntu docker image. Create a container for salt minion $  docker run -ti --name salt-minion-agent    --net=none --privileged=true ubuntu:14.04.5 bash This will create a container, we will use the same container to install salt minion. Now configure the network for this container. ASSIGNING AN IP FOR A CONTAINER Here I am assuming that host machine is having interface "eth0" with public IP configured.  Name of the container is salt-minion-agent.  The below steps needs to b...
Running Salt Master In Docker Container From Scratch  In this post, we will install salt master in docker container and configure the public IP so it will be reachable from outside. Prerequisites:     Ubuntu host up and running. Public IP should be configured. Docker should be installed. Skip to end of metadata Go to start of metadat Pull Ubuntu docker image $  docker pull   ubuntu:14.04.5 It will download the Ubuntu docker image. Create a container for salt master $  docker run -ti --name salt-master-server   --net=none --privileged=true ubuntu:14.04.5 bash This will create a container, we will use the same container to install salt master. Now configure the network for this container. Assigning an IP for a container Here I am assuming that host machine is having interface "eth0" with public IP configured.  Name of the container is salt-master-server.  The below steps needs to be per...
Monitor Any Java Process With Jolokia Hello, friends, I am writing this post because I struggled a lot to find out the solution for this. I was having a running java application on my machine and I wanted to monitor the performance  of that application. There are various tools to monitor the java process like: JConsole Jolokia You will find many posts about monitoring java process through JConsol, So let's not discuss that topic here anymore. In this post, we are going to discuss the Jolokia. To Monitor any java process via Jolokia fellow below steps: Download Jolokia JVM agent from here: https://jolokia.org/download.htm l e.g.  jolokia-jvm-1.5.0-agent.jar Assuming that you are having a running java process in your machine with PID  1234 Start the Jolokia JVM agent by running below command to monitor a java process java -jar jolokia-jvm-1.5.0-agent.jar start 1234              ...