Docker

Create a MAC VLAN network

Description

The command below is an example of creating a layer 2 macvlan network in docker. In the example below, the network I am using is 10.128.140.0/24 on interface ens160. You will have to replace the subnet and interface according to your install.

Conifguration

docker network create -d macvlan --subnet=10.128.140.0/24 --gateway 10.128.140.1 -o parent=ens160 L2-Connect

and this is how you add a VLAN network

docker network create -d macvlan --subnet=172.16.8.0/22 --gateway 172.16.8.1 -o parent=ens192.40 Data-40-L2-Connect

After creation of the network you can take a look to make sure it exists

root@container:~# docker network ls

NETWORK ID     NAME         DRIVER    SCOPE

01734d37ed78   L2-Connect   macvlan   local

310563fabcd7   bridge       bridge    local

4bc024cbd7cc   host         host      local

d2879a267450   none         null      local

Deploy Portainer on a MAC VLAN network

Description

On the previous page I showed how to create a layer 2 macvlan network that allows you to deploye containers in the same network as the host itself. This example will show you how to deploye Portainer CE using the layer 2 macvlan network we created.

Configuration

root@container:~# docker run -d --network L2-Connect --ip=10.128.140.31 --dns=1.1.1.1 --name=Portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

Once the container has been created you can run the docker container ls command to see the deployed container.

root@container:~# docker container ls

CONTAINER ID   IMAGE                           COMMAND        CREATED          STATUS          PORTS     NAMES

cd30907cabe6   portainer/portainer-ce:latest   "/portainer"   10 minutes ago   Up 10 minutes             Portainer