Preface
In usedocker build
Command buildDocker
When encountering the situation where the network cannot be connected during mirroring, there may be many situations.
Check host network settings
Check if your host is configured with a proxy server or firewall, which may prevent itDocker
Containers access external network.
If your host uses a proxy server, make sureDocker
The container has properly configured proxy settings.
If your host has a firewall running, please allowDocker
Containers access external network.
Test the host's network connection
ping
Test whether the host can access external network.
If the host cannot access the external network, it may be caused by a host network setup error or a network failure.
Test the host's DNS resolution
nslookup
Test whether the host can successfully resolve the domain name toIP
address.
ifDNS
The resolution failed, which may be due to the host's domain name server setting error orDNS
A result of a server failure.
Test the proxy server connection of the host
If you have configured the proxy service, you can test it through the following, which will useHTTP
Proxy server connection towebsite.
You need toand
port
Replace with the actual proxy server address and port number.
If the connection is successful, it means the host's proxy server is set correctly.
curl -x :port
Check Docker network settings
CheckDocker
Network List
docker network ls
This will list all availableDocker
network.
By default,Docker
Three networks are created during installation:bridge
、host
andnone
。
CheckDocker
Network details
docker network inspect <network-name>
This will display the specifiedDocker
Network details, including networkIP
Address range, gateway, domain name server, etc.
Test Docker network connection
docker run --rm --network=<network-name> alpine ping <ip-address>
This will be specified in theDocker
Run one in the networkAlpine
Container and useping
Command test specificationIP
The connection of the address.
You need to<network-name>
Replace with actualDocker
Network name,<ip-address>
Replace with the IP address to be tested.
If the connection is successful, it meansDocker
The network settings are correct.
The sample code is as follows:
docker run --rm --network=host alpine ping
testdocker
Using the host machinehost
Run one in the network situationAlpine
Container and useping
Command Test。
Proxy server configuration
If your host is using a proxy server, make sureDocker
The container has properly configured proxy settings.
For example, you can add the following command toDockerfile
In the file:
ENV http_proxy ":port" ENV https_proxy ":port"
This willDocker
Settings in containersHTTP
andHTTPS
Proxy server.
You need toand
port
Replace with the actual proxy server address and port number.
There is another possibility that you need to configure the mirror source to access packages in mainland China faster:
RUN sed -i s@//@//@g /etc/apt/ RUN sed -i s@//@//@g /etc/apt/ RUN sed -i s@//@//@g /etc/apt/ RUN sed -i s@//@//@g /etc/apt/
Rebuild the image
If you have done the above steps but still can't connect to the internet, try rebuilding the image.
It is best to clear the old mirror cache before rebuilding to ensureDocker
Use the latestDockerfile
Files and configurations.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.