我有一个正在运行的 docker 容器Ubuntu 18.04
。
我使用以下命令运行它,但是如果我关闭接口,无论我做什么,即使它说接口已启动,我也无法再与其建立任何连接。
docker run --hostname=hello.world --cap-add=NET_ADMIN -it test-ubuntu18
在我的容器中,我曾经ip link set eth0 down
暂时禁用网络,但是一旦我重新打开它,就没有任何作用。
这是我的 Dockerfile
FROM ubuntu:18.04 as base
# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
apt-transport-https build-essential ca-certificates curl dbus git \
iputils-ping libssl-dev net-tools network-manager vim wget systemd \
sudo rsyslog
ENV NVM_DIR /root/.nvm
ENV NODE_VERSION 17
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# Fix rsyslog start up by disable imklog
RUN sed -i 's/module(load="imklog"/#module(load="imklog"/' /etc/rsyslog.conf
ENTRYPOINT service rsyslog start && \
service dbus start && \
service network-manager start && \
bash
有谁知道是否可以使用 docker 容器重新启用网络?
root@hello:~# ping google.com
PING google.com (172.217.13.110) 56(84) bytes of data.
64 bytes from 172.217.13.110 (172.217.13.110): icmp_seq=1 ttl=63 time=11.9 ms
64 bytes from 172.217.13.110 (172.217.13.110): icmp_seq=2 ttl=63 time=14.0 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 11.982/13.011/14.041/1.035 ms
root@hello:~# ip link set eth0 down
root@hello:~# ping google.com
ping: google.com: Temporary failure in name resolution
root@hello:~# ip link set eth0 up
root@hello:~# ping google.com
ping: google.com: Temporary failure in name resolution
root@hello:~# 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
269: eth0@if270: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0