Today I pull an image from the Internet, and I found that the docker networking mode can be detected in the image's startup script. But docker0 only exists in the host not the container. Why? Dockerfile
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -y net-tools \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD test/ /etc/test/
RUN chmod +x /etc/test/*.sh
CMD ["/bin/bash", "/etc/test/start.sh"]
start.sh
#!/bin/sh
set -e
# check for presence of network interface docker0
check_network=$(ifconfig | grep docker0 || true)
# if network interface docker0 is present then we are running in host mode and thus must exit
if [[ ! -z "${check_network}" ]]; then
echo "[crit] Network type detected as 'Host', this will cause major issues, please stop the container and switch back to 'Bridge' mode" | ts '%Y-%m-%d %H:%M:%.S' && exit 1
fi
I run it with docker run --privileged --net=host
will get
[crit] Network type detected as 'Host', this will cause major issues, please stop the container and switch back to 'Bridge' mode