我在这里包含了代码.. https://github.com/vinceyoumans/achal
问题: docker compose 文件中的两个容器。一个是标准的 Postgress 容器。第二个是 goLang Scratch 容器。当 postgres 连接失败时,GoLang main.go 文件会崩溃。你可以在github上看到代码。
请求: 查看 main.go 和 dockercompose 文件,看看这个网络有什么问题……我错过了什么。
db, err := gorm.Open("postgres", "host='postgres' port=5432 user=docker dbname='docker' password='password'")
if err != nil {
fmt.Println("============ exiting ==========")
fmt.Println(err)
panic("failed to connect database e")
// the error i get... dial tcp: lookup postgres on 127.0.0.11:53: no such host
// panic("failed to connect database: " + err)
}
docker-compose.yml
version: '3.6'
services:
postgre:
image: postgres:11.1-alpine
ports:
- '5432:5432'
#network_mode: bridge
#container_name: postgres
environment:
POSTGRES_USER: 'user'
POSTGRES_PASSWORD: 'password'
POSTGRESS_DB: 'db_amex01'
volumes:
- ./init:/docker-entrypoint-initdb.d/
todo:
build: ./go_amex/
# ports:
# - "8000:8080"
# sudo docker-compose -f docker-compose.yml up
# HELP: how would I add the goLang service from this point?
长风秋雁
12345678_0001
杨__羊羊
相关分类