Assign public IP address to Docker Container without port binding.

MACVLAN creates multiple virtual network interfaces with different MAC addresses. This way if your system has multiple IP addresses with MAC addresses then we can create multiple virtual network interfaces each having their own IP address and MAC address.

MACVLAN doesn’t need to learn(identify) mac addresses of the systems within the network to distribute traffic as it know’s every mac address, this makes it fast and easy to setup than bridge type networking.

Problems with docker containers port binding:

  • If a container uses port 8000 of host then no other containers can use that port.

  • Binding multiple ports to container can be done by specifying port range but this operation takes more time depending on no. of ports to bind.

  • IPTables rules become cumbersome as no. of bindings increase.

Advantages of MACVLAN:

  • IPTables aren’t affected.

  • No port binding.

  • Easy to setup.

  • Faster than bridge networking.

Creating MACVLAN network:


Host IP:

Host subnet:

Host Mask: 26

Host gateway:

Host ethernet interface: eth0

docker network create -d macvlan -o macvlan_mode=bridge --subnet= --gateway= -o parent=eth0 macvlan_bridge

Above command creates network named ‘macvlan_bridge’

Running a container using ‘macvlan_bridge’ network:


Host contains multiple publicly accessible IP addresses with MAC addresses.

Host additional IP/MAC:

docker run --name cont1 --net=macvlan_bridge --ip= --mac-address 00:50:56:00:60:42 -itd nginx

Above command runs nginx container with ip ‘’ attached to this container, you can verify by hitting ‘’ where you will be welcomed with nginx page.

This way overall network setup will become clear and easy to handle.

Posted On 13 February 2017 By MicroPyramid

About Micropyramid

Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.

Need any Help in your Project?Let's Talk


Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
*We don't provide your email contact details to any third parties