0

This is the docker compose file. The only thing I have changed is adding a command so that hasura would wait until the website is up before spinning up the image.

version: "3.8"
services:
  graphql-engine:
    container_name: "prm_graphql_engine"
    image: hasura/graphql-engine:v1.3.0
    ports:
      - "8080:8080"
    command: >
      sh -c "
      until wget --spider host.docker.internal:8000; do
        >&2 echo 'Django is unavailable - sleeping'
        sleep 5
      done;
        echo 'Django is up'
      "
    depends_on:
      - "db"
      - "web"
    restart: always
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@db:5432/$POSTGRES_NAME
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log

When I run docker-compose up verbose, here is the error message.

prm_graphql_engine exited with code 0
urllib3.connectionpool._make_request: http://localhost:None "POST /v1.38/containers/d3be369d69af7de6cd5dc84f0056dda49fce7f474b827e78e518144dca8e03d5/wait HTTP/1.1" 200 None
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.38/containers/d3be369d69af7de6cd5dc84f0056dda49fce7f474b827e78e518144dca8e03d5/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['-c',
          ' until wget --spider host.docker.internal:8000; do\n'
          "  >&2 echo 'Django is unavailable - sleeping'\n"
          '  sleep 5\n'
          'done;\n'
          "  echo 'Django is up'\n"],
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('d3be369d69af7de6cd5dc84f0056dda49fce7f474b827e78e518144dca8e03d5')

Is there something I missed? I do need to wait for another container to run first but I don't see why the command would cause any error.

Thomas Ng
  • 73
  • 7

1 Answers1

2

Exit code 0 is success (easy to remember, all non-zero exit codes = failure).

It looks like what's happened here is that command in the docker-compose.yaml overrides the default command. And you've set the command to be:

until wget --spider host.docker.internal:8000; do
        >&2 echo 'Django is unavailable - sleeping'
        sleep 5
done;
echo 'Django is up'

Assuming that the until condition is met, and it goes on to echo, once it finishes that command would terminate with exit code 0, and then end the container process (preventing Hasura from running).

I think you should use a docker-entrypoint script if you want to execute pre-start commands instead of overriding the container's command.

Gavin Ray
  • 595
  • 1
  • 3
  • 10
  • Thank you and this does answer my question. Could you share how to not override the original entrypoint or cmd? I have actually tried both and it seems like they both overrode the original cmd/entrypoint commands. – Thomas Ng Jul 25 '20 at 15:06