Docker 提供网络功能,使容器可以彼此通信,也可以与外部世界通信。端口映射将容器的端口暴露到主机,网络让容器可以按名称相互通信。理解基础知识对于运行连接的应用程序至关重要。
端口映射 — 将容器暴露到主机
# -p HOST_PORT:CONTAINER_PORT maps a host port to a container port
docker run -p 8080:80 nginx
# → nginx listens on port 80 INSIDE the container;
# accessing localhost:8080 on the HOST reaches it
