英文:
Golang: `dial tcp 172.20.0.7:8081: connect: connection refused`, error at random times between docker containers / services
问题
我有一个包含以下内容的docker-compose
文件:
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)
version: '3'
services:
john:
build:
context: .
dockerfile: Dockerfiles/cowboys/John/Dockerfile
args:
- COWBOY_NAME_JOHN
- CONTAINER_PORT_JOHN
ports:
- "8081:8081" # 将容器上的暴露端口转发到主机上的端口
restart: unless-stopped
networks:
- fullstack
depends_on:
db:
condition: service_healthy
links:
- db
philip:
build:
context: .
dockerfile: Dockerfiles/cowboys/Philip/Dockerfile
args:
- COWBOY_NAME_PHILIP
- CONTAINER_PORT_PHILIP
ports:
- "8085:8085"
restart: unless-stopped
networks:
- fullstack
depends_on:
db:
condition: service_healthy
links:
- db
db:
build:
context: Dockerfiles/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
restart: on-failure
networks:
- fullstack
ports:
- "3306:3306"
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
networks:
fullstack:
driver: bridge
当我运行docker-compose up --build
(或者在下一次运行时重新初始化数据库时运行docker-compose up --build --force-recreate
)时,我会得到以下错误:
sam_1 | panic: Put "http://john:8081/shoot": dial tcp 172.20.0.7:8081: connect: connection refused
john
是services
下的一个服务名称。这是完整的屏幕截图:
包含环境变量和相关Dockerfile的详细信息的存储库链接 - https://github.com/sitetester/distributed-cowboys
请问有人可以解释如何解决这个错误吗?它只是在随机时间发生。不确定如何修复。提前感谢!
英文:
I've a docker-compose
file with contents like this
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)
version: '3'
services:
john:
build:
context: .
dockerfile: Dockerfiles/cowboys/John/Dockerfile
args:
- COWBOY_NAME_JOHN
- CONTAINER_PORT_JOHN
ports:
- "8081:8081" # Forward the exposed port on the container to port on the host machine
restart: unless-stopped
networks:
- fullstack
depends_on:
db:
condition: service_healthy
links:
- db
philip:
build:
context: .
dockerfile: Dockerfiles/cowboys/Philip/Dockerfile
args:
- COWBOY_NAME_PHILIP
- CONTAINER_PORT_PHILIP
ports:
- "8085:8085"
restart: unless-stopped
networks:
- fullstack
depends_on:
db:
condition: service_healthy
links:
- db
db:
build:
context: Dockerfiles/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
restart: on-failure
networks:
- fullstack
ports:
- "3306:3306"
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
networks:
fullstack:
driver: bridge
When I run docker-compose up --build
( or docker-compose up --build --force-recreate
to reinitialise db on next run), I get an error like this
sam_1 | panic: Put "http://john:8081/shoot": dial tcp 172.20.0.7:8081: connect: connection refused
john
is one of the services name under services
. Here is complete screenshot:
Link to repository where all details could be seen including environment variables & relevant Dockerfile(s) - https://github.com/sitetester/distributed-cowboys
Could anyone please explain how to get rid of this error ? It just happens/occurs at random time. Not sure how to fix it. Thanks in advance!
答案1
得分: 1
已解决:删除现有的容器/镜像并清理 Docker 卷解决了该问题。
英文:
Solved: removing existing containers/images and pruning docker volumes fixed the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论