![](/img/trans.png)
[英]dial tcp 127.0.0.1:8000: connect: connection refused golang docker containers
[英]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" # 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
當我運行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 下的services
名稱之一。 這是完整的屏幕截圖:
鏈接到可以看到所有詳細信息的存儲庫,包括環境變量和相關的 Dockerfile - https://github.com/sitetester/distributed-cowboys
誰能解釋一下如何擺脫這個錯誤? 它只是隨機發生/發生。 不知道如何解決它。 提前致謝!
已解決:刪除現有容器/圖像並修剪 docker 卷解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.