You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Enable-host-to-container-networking.sh
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,12 @@
2
2
3
3
#Change these variables!
4
4
NIC_NAME="eth0"
5
-
DOCKERNETWORK_NAME="dockervlan"
5
+
DOCKER_ROUTING_INTERFACE_NAME="dockerrouteif"
6
6
DOCKERNETWORK_IP_ADDRESS="192.168.0.249/32"
7
7
DOCKERNETWORK_IP_RANGE="192.168.0.64/26"
8
8
9
9
sleep 15 #Do not rush things if executing during boot. This line is not mandatory and can be removed.
10
10
11
11
12
-
ip link add ${DOCKERNETWORK_NAME} link ${NIC_NAME}type macvlan mode bridge ; ip addr add ${DOCKERNETWORK_IP_ADDRESS} dev ${DOCKERNETWORK_NAME}; ip link set${DOCKERNETWORK_NAME} up
13
-
ip route add ${DOCKERNETWORK_IP_RANGE} dev ${DOCKERNETWORK_NAME}
12
+
ip link add ${DOCKER_ROUTING_INTERFACE_NAME} link ${NIC_NAME}type macvlan mode bridge ; ip addr add ${DOCKERNETWORK_IP_ADDRESS} dev ${DOCKER_ROUTING_INTERFACE_NAME}; ip link set${DOCKER_ROUTING_INTERFACE_NAME} up
13
+
ip route add ${DOCKERNETWORK_IP_RANGE} dev ${DOCKER_ROUTING_INTERFACE_NAME}
Copy file name to clipboardExpand all lines: README.md
+7-6Lines changed: 7 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -10,19 +10,19 @@ You can reach the container with custom defined IP address from any host on the
10
10
Check the **Enable-host-to-container-networking.sh** script file or manual steps defined.
11
11
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:
12
12
13
-
* Create new interface (Interface name is *dockervlan*, and *eth0* is the host interface):
14
-
`ip link add dockervlan link eth0 type macvlan mode bridge`
13
+
* Create new interface (Interface name is *dockerrouteif*, and *eth0* is the host interface):
14
+
`ip link add dockerrouteif link eth0 type macvlan mode bridge`
15
15
16
16
* 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:
17
-
`ip addr add 192.168.0.249/32 dev dockervlan`
17
+
`ip addr add 192.168.0.249/32 dev dockerrouteif`
18
18
**NOTE: Ensure defined IP address is not used by another host/device/container though!**
19
19
**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**
20
20
21
21
* Bring up that interface:
22
-
`ip link set dockervlan up`
22
+
`ip link set dockerrouteif up`
23
23
24
24
* And finally define a range which should be routed trough that iterface:
25
-
`ip route add 192.168.0.64/26 dev dockervlan`
25
+
`ip route add 192.168.0.64/26 dev dockerrouteif`
26
26
27
27
Lastly, bring up the docker compose file:
28
28
`docker-compose up -d`
@@ -33,6 +33,7 @@ Host interface name: `eth0`
33
33
Gateway: `192.168.0.1`
34
34
Subnet: `192.168.0.0/24`
35
35
Host IP: `192.168.0.2`
36
-
Interface name trough which traffic is routed: `dockervlan`
36
+
Interface name trough which traffic is routed: `dockerrouteif`
Copy file name to clipboardExpand all lines: ansible/playbooks/roles/docker-compose-macvlan/templates/Enable-host-to-container-networking.sh.j2
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,5 +2,5 @@
2
2
3
3
sleep 15 #Do not rush things if executing during boot. This line is not mandatory and can be removed.
4
4
5
-
ip link add {{ dockernetwork_name }} link {{ nic_name }} type macvlan mode bridge ; ip addr add {{ dockernetwork_ip_address }} dev {{ dockernetwork_name }} ; ip link set {{ dockernetwork_name }} up
6
-
ip route add {{ dockernetwork_ip_range }} dev {{ dockernetwork_name }}
5
+
ip link add {{ docker_routing_interface_name }} link {{ nic_name }} type macvlan mode bridge ; ip addr add {{ dockernetwork_ip_address }} dev {{ docker_routing_interface_name }} ; ip link set {{ docker_routing_interface_name }} up
6
+
ip route add {{ dockernetwork_ip_range }} dev {{ docker_routing_interface_name }}
0 commit comments