docker容器里能联网么
Docker 容器里能联网么?
Docker containers can connect to the internet if they are using the right network. By default, containers are not able to connect to the internet. This is because the default network for containers only allows connections between containers on the same host.
To allow a container to connect to the internet, you need to use a different network. There are many different networks that you can use, but the most common one is the bridge network.
The bridge network will allow containers to connect to the internet if the host has an internet connection. To create a bridge network, you can use the docker network create command.
docker network create --driver bridge my-bridge-network
Once the network is created, you can start containers on the network.
docker run --net my-bridge-network --name my-container -d busybox
Now that the container is running, you can test the internet connection.
docker exec -it my-container ping www.google.com
If the container can ping www.google.com, then it has an internet connection.
相关文章