drrvnbwle80177811 2018-08-17 20:53
浏览 298
已采纳

Postgres,Go Docker编写wait-for-it.sh没有此类文件或目录

Been racking my head about this one for almost two days.

I'm new to Docker and Docker Compose, and trying to run my image on an EC2 instance running Postgres and Go. When I run docker-compose up, the db service runs successfully, but not the app service.

When I try to run the services separately using:

docker-compose up db all is good

then run:

docker-compose up app I get...

app_1  | wait-for-it.sh: waiting 15 seconds for db:5432
app_1  | wait-for-it.sh: db:5432 is available after 0 seconds
app_1  | ./wait-for-it.sh: line 174: /go/src/github.com/MY_USERNAME/MY_APP_DIR/EXECUTABLE: No such file or directory
some_name-golang_app_1 exited with code 127

Dockerfile-alternate:

FROM  golang:latest

EXPOSE 8080

WORKDIR /go/src/github.com/MY_USERNAME/MY_APP_DIR
ADD . /go/src/github.com/MY_USERNAME/MY_APP_DIR

# Install all dependencies of the current project.
RUN go get -v
RUN go build

docker-compose.yml

version: '3'
services:
  db:
      image: postgres
      environment:
          POSTGRES_DB: dbname
          POSTGRES_USER: miller
          POSTGRES_PASSWORD: miller
      ports:
        - "6000:5432"
  app:
    build:
      context: .
      dockerfile: Dockerfile-alternate
    command: ["./wait-for-it.sh", "db:5432", "--", "./EXECUTABLE"]
    volumes:
      - .:/go/src/github.com/gregpmillr/volume
    ports:
      - "80:8080"
    depends_on:
        - db
    links:
        - db

Interestingly enough, if I run docker run -it --rm MY_USERNAME/custom-go-image then I actually do see the EXECUTABLE file, and can run ./EXECUTABLE successfully... Well sort-of, I get a no such host error but pretty sure that's because I'm not starting them at the same time using docker-compose.

Any thought on this issue? Tips / resources would be great. I've been heading down rabbit holes of googling issues and leading nowhere. It's probably something small that I'm missing as per usual. Thanks!!

I'm looking to run postgres first (works correctly now), then run the go server which connects to postgres.

UPDATE 1

command: [ "sh", "-c", "cd /go/src/github.com/gregpmillr/volume && ls -l" ]

will give the following output:

db_1   | 2018-08-19 11:19:48.828 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2018-08-19 11:19:48.828 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2018-08-19 11:19:48.831 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-08-19 11:19:48.857 UTC [21] LOG:  database system was shut down at 2018-08-19 01:03:35 UTC
db_1   | 2018-08-19 11:19:48.880 UTC [1] LOG:  database system is ready to accept connections
app_1  | total 36
app_1  | -rw-rw-r-- 1 1000 1000  238 Aug 19 11:19 Dockerfile-alternate
app_1  | -rw-rw-r-- 1 1000 1000  260 Aug 17 19:24 Dockerrun.aws.json
app_1  | -rw-rw-r-- 1 1000 1000   62 Aug 17 18:56 README.md
app_1  | drwxrwxr-x 8 1000 1000 4096 Aug 17 19:00 app
app_1  | drwxrwxr-x 2 1000 1000 4096 Aug 17 19:34 config
app_1  | -rwxrwxr-x 1 1000 1000  708 Aug 17 19:48 deploy.sh
app_1  | -rw-rw-r-- 1 1000 1000  548 Aug 19 11:19 docker-compose.yml
app_1  | -rw-rw-r-- 1 1000 1000 1188 Aug 17 19:00 main.go
app_1  | -rwxrwxr-x 1 1000 1000 4079 Aug 17 19:00 wait-for-it.sh
app_1 exited with code 0

Dockerrun file is unnecessary as I'm not using elastic beanstalk atm.

UPDATE 2 Solved. See accepted answer. More specifically, see https://docs.docker.com/storage/ and https://docs.docker.com/storage/volumes/ for more info on Volumes. Thanks for the help!

  • 写回答

1条回答 默认 最新

  • dongrao9436 2018-08-19 12:43
    关注

    You've added the go source code into your image and compiled it inside the image as part of your build. Then you overlaid that same path with a volume containing your source code (apparently without a compiled binary) by including the following:

    volumes:
      - .:/go/src/github.com/gregpmillr/Tranquility-Online-Golang
    

    You either need the compiled binary in that volume, or skip mounting the volume into the container since it is blocking access to the files in your image.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 基于同花顺supermind的量化策略脚本编辑
  • ¥20 Html备忘录页面制作
  • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?
  • ¥20 数学建模来解决我这个问题
  • ¥15 计算机网络ip分片偏移量计算头部是-20还是-40呀
  • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?