0

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!

11
  • Did you try making wait-for-it print the output of ls -l inside the ../MY_APP_DIR/ directory and see if the executable is visible to the script? Commented Aug 17, 2018 at 21:09
  • 1
    ... also you've included a Dockerfile in the question but your compose file builds the contrainer from an image, what's the Dockerfile for? Is it even being used? If not then the reason the executable isn't there might be because the RUN go build, which is in the Dockerfile, is never executed. Commented Aug 17, 2018 at 21:23
  • ... try using this docs.docker.com/compose/compose-file/#build with the dockerfile key instead of using the image. Commented Aug 17, 2018 at 21:28
  • 2
    From your docker-compose file try removing the volumes:\n - .:/go/src/github.com/gregpmillr/Tranquility-Online-Golang line under the app service, I think it might be overshadowing the contents of the image that live at the same directory path. Commented Aug 19, 2018 at 12:10
  • 1
    worked! Thanks for all your patience and help @mkopriva !!! Commented Aug 19, 2018 at 19:26

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I assumed the volume would just be created beforehand and used from the Docker host, but wasn't aware it would override existing files, as outlined in this documentation: docs.docker.com/storage/volumes/#remove-anonymous-volumes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.