[Docker] Allow Containers to Communicate through Docker Networks
Docker to Networks Through Allow Containers
2023-09-14 09:00:46 时间
Docker containers that are running on your local machine can't communicate with each other. In this mini post explains why and shows a demonstration of Docker networks.
Create two containers:
docker run -it -d --rm --name one alpine /bin/sh docker run -it -d --rm --name two alpine /bin/sh // -it -d: run in interactive mode and in background // once container is running, enter /bin/sh mode // use apline as base image
Entering 'one' container and run /bin/sh
docker exec -it one /bin/sh
If you try to ping container 'two', you will get a bad address error, because two containers are isolated.
ping two
Run:
exit
docker stop one
docker stop two
In order to let two container talk to each other, we need 'network':
docker network create alpine-network
Add two containers into network:
docker run -it -d --rm --name one --network alpine-network alpine /bin/sh
docker run -it -d --rm --name two --network alpine-network alpine /bin/sh
You can see the configurations:
docker network inspect alpine-network
Entering one container:
docker exec -it one /bin/sh
ping two
Now two container should be able to communicate each other
相关文章
- Docker实践:GO Docker部署与打包实例
- 远程调试docker 容器中的java
- 【Docker】iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8480 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name
- 解决: Got permission denied while trying to connect to the Docker daemon socket
- [Docker] Allow Containers to Communicate through Docker Networks
- [Docker] Linking Node.js and MongoDB Containers
- Docker为整个软件生命周期提供安全保障
- [Docker] Push container to Docker hub
- k3s containerd和docker命令对比表
- 解决docker push镜像到私有仓库时的报错【http: server gave HTTP response to HTTPS client】
- 成功解决Docker Desktop requires Windows 10 Pro or Enterprise version 15063 to run.
- 【已】Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
- 【ubuntu】解决“Unable to locate package docker.io”问题
- Centos7 安装docker ce
- How to set up a Headless Chrome Node.js server in Docker
- 【Docker】在本地打包maven程序为docker镜像报错: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]
- 监控docker容器运行状态脚本shell
- WSL2之docker编译android12报错:Build sandboxing disabled due to nsjail error.
- CentOS系统安装Docker Engine
- 【实操】使用 Zeabur 和 docker 两种方式部署 ChatGPT 详细教程
- centos实现docker环境的搭建
- docker企业级私有仓库harbor部署配置(十三)