'Docker container mac address change
I have an application that uses a MAC Address for licensing. I'd like to run this application in a docker container for CI/CD purposes. I created a docker container and use the ENTRYPOINT to run a shell script. The issue I am running into now is that when I try to ping any server I get network errors. I am wondering if this is something that I can fix or if I am doing this incorrectly. I'd love to find a solution for this so I can test scripts that I write for this system before pushing them to production. I'll be around to answer any additional questions.
Dockerfile
FROM centos:latest
COPY startup.sh /startup.sh
ENTRYPOINT ["/bin/sh", "/startup.sh"]
startup.sh
ip link set dev eth0 down;
ip link set dev eth0 address 02:42:ac:11:00:11;
ip link set dev eth0 up;
Errors
sh-4.4# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
29: eth0@if30: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
link/ether 02:42:ac:11:00:11 brd ff:ff:ff:ff:ff:ff link-netnsid 0
sh-4.4# ping google.com
ping: google.com: Name or service not known
sh-4.4# ping 4.4.4.4
connect: Network is unreachable
Solution 1:[1]
If you need to override low-level networking details like this, you should generally do it at the Docker level. For example, there is a docker run --mac-address option that you can specify when you launch the container. You shouldn't need to run ip, ifconfig, or similar network-management commands in your container's startup sequence; this is entirely handled by Docker.
docker run --mac-address 02:42:ac:11:00:11 ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Maze |
