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.

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

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置