GithubHelp home page GithubHelp logo

occoder / docker-compose-macvlan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sarunas-zilinskas/docker-compose-macvlan

0.0 0.0 0.0 14 KB

Docker-compose macvlan example - container using different IP address than host.

Shell 61.47% Jinja 38.53%

docker-compose-macvlan's Introduction

docker-compose-macvlan

Docker-compose example using macvlan driver. Example using ansible is included! See ansible folder

This docker-compose file creates a network using macvlan driver and deploys portainer container (Used just as an example) attaching it to the same newly created network.
This gives you the ability to deploy containers with custom static IP address which is different from the host IP address - and all of it without DHCP reservations! (Ensure defined IP address is not used by another host/device/container though!).
You can reach the container with custom defined IP address from any host on the same LAN, however you can not reach it from the host machine itself (Below are instructions how to mitigate this).

Enable host to container networking:

Check the Enable-host-to-container-networking.sh script file or manual steps defined.
For making container accessible within the same host - one needs to create ethernet interface and route the containers used IP address (or range) trough the new interface:

  • Create new interface (Interface name is dockerrouteif, and eth0 is the host interface):
    ip link add dockerrouteif link eth0 type macvlan mode bridge

  • Then assign IP address to that interface (Imagine it as a gateway - just like a router works but without NAT). In this example I used 192.168.0.249:
    ip addr add 192.168.0.249/32 dev dockerrouteif
    NOTE: Ensure defined IP address is not used by another host/device/container though!
    NOTE: If you check logs i.e. host is using DNS server which is in a container, any requests made from the host will be seen as coming from this IP

  • Bring up that interface:
    ip link set dockerrouteif up

  • And finally define a range which should be routed trough that iterface:
    ip route add 192.168.0.64/26 dev dockerrouteif

Lastly, bring up the docker compose file:
docker-compose up -d
Success! Portainer now should be accessible from the host machine and all other machines within the same subnet/network!

Network used in the example:

Host interface name: eth0
Gateway: 192.168.0.1
Subnet: 192.168.0.0/24
Host IP: 192.168.0.2
Interface name trough which traffic is routed: dockerrouteif
Docker VLAN name: Dockervlan Dockervlan interface IP: 192.168.0.249
dockervlan routed IP range: 192.168.0.64/26

docker-compose-macvlan's People

Contributors

sarunas-zilinskas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.