Skip to content

Instantly share code, notes, and snippets.

@phillijw
Forked from aaronstaves/macvlan-physical.md
Created September 5, 2018 02:19
Show Gist options
  • Save phillijw/bc5d33de72821df7741a0dfca3d5ac67 to your computer and use it in GitHub Desktop.
Save phillijw/bc5d33de72821df7741a0dfca3d5ac67 to your computer and use it in GitHub Desktop.
Notes on making a macvlan physical network and container attached

Create a network on the host interface

Prereqs

  1. Setup the network that you'll be connecting to to only allow dhcp within a certain range
  2. Use the unreserved dhcp range for docker

Example

I'm using 192.168.1.2 - 192.168.1.199 as my DHCP range.
All my docker containers are going to be limited to the ip range of 192.168.1.224 - 192.168.1.254 (--ip-range=192.168.1.224/27)

Setup

Create a network

This will create a docker network called "physical" docker network create -d macvlan --subnet=192.168.1.0/24 --ip-range=192.168.1.224/27 --gateway=192.168.1.1 -o parent=eth0 physical

Create a docker compose file (don't have to do this if you're using the cli)

version: '2.2'
services:
  web:
    container_name: nginx
    image: nginx
    restart: always
    volumes:
      - /data/nginx/conf.d:/etc/nginx/conf.d:ro
      - /data/nginx/www/:/var/www:ro
      - /data/nginx/certs/letsencrypt:/etc/letsencrypt:ro
      - /data/nginx/ssl:/etc/nginx/ssl:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    hostname: docker-nginx
    networks:
      physical:
        # IP ADDRESS TO MANUALLY ASSIGN TO CONTAINER
        ipv4_address: 192.168.1.225

# Tell the compose file that the network you created "physical" is out there and created
networks:
  physical:
    external: true

Create

docker-compose up -d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment