drrvnbwle80177811
drrvnbwle80177811
2018-08-17 20:53
浏览 229

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
    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.

    点赞 评论

相关推荐