Create a network on the host interface
- Setup the network that you'll be connecting to to only allow dhcp within a certain range
- Use the unreserved dhcp range for docker
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)
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
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
docker-compose up -d