Introduction
A docker container should be accessable from an IPv4 address that is not the original IP of the Docker host. This is possible with the IPvLAN driver. This article will show how to configure a Docker container with an external IP using Docker Compose and IPvLAN.
Prerequisites
- install Docker
- install Docker Compose
Docker Compose
- create a
docker-compose.ymlfile with the following content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---
version: '3.8'
networks:
lan:
driver: ipvlan
driver_opts:
parent: enp0s31f6
ipam:
driver: default
config:
- subnet: 10.0.0.0/24
gateway: 10.0.0.1
ip_range: 10.0.0.3/32
services:
web:
image: nginx:latest
container_name: web
restart: always
networks:
lan:
ipv4_address: 10.0.0.3
ports:
- 80
enp0s31f6is the name of the network interface on the Docker host that is connected to the network where the container should be reachable from10.0.0.0/24is the network where the container should be reachable from10.0.0.1is the gateway of the network10.0.0.3/32is the IP address range for Docker containers10.0.0.3is the IP address of the container we’d like to deploy- start the container with
docker-compose up -d