doupao5296 2019-04-06 08:23
浏览 114

无法从api服务连接到docker容器中的db主机到db服务以便使用golang中的goose进行迁移

goose is the migration tool that helps me to run all the *sql files and run up queries within database. I want to automate migrations(create tables and stuff) using this tool within the docker container on my api service. The problem is when docker runs command "goose run" it gets an error -goose run: dial tcp: lookup db on 192.168.63.6:53: no such host.

docker-compose

services:
  db:
    build: ./db
    volumes:
      - ./db/pgdata:/pgdata
    image: postgres
    ports:
      - "5432"
    restart: always
    environment:
      - POSTGRES_USER=user
      - POSTGRES_DB=dbname
      - POSTGRES_PASSWORD=123
      - PGDATA=/pgdata

  api:
    build:
      context: ./api
    restart: always
    volumes:
      - ./api:/go/src/github.com/gitlees/todoapp/api
    ports:
      - "5000:8080"
    links: 
      - "db"

Api Dockerfile

RUN go get -u github.com/pressly/goose/cmd/goose

RUN goose postgres "host=db user=user dbname=dbname sslmode=disable password=123" up
  • 写回答

2条回答 默认 最新

  • douliao5942 2019-04-06 11:22
    关注

    RUN commands are executed during build phase. During this phase there is no container yet.

    Commands that are meant to connect to other containers should be defined in CMD or ENTRYPOINT in the Dockerfile.

    评论

报告相同问题?

悬赏问题

  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'