1

In this example, I want to run prisma container, only when mysql container is exposed on mysql:3036. I tried to use wait-for-it.sh but how can I use this inside prisma container? https://github.com/vishnubob/wait-for-it

version: '3.7'
services:
  prisma:
    image: prismagraphql/prisma:1.34.8
    restart: always
    depends_on:
      - mysql
    ports:
      - '4466:4466'

    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: mysql
            host: mysql
            user: root
            password: prisma
            rawAccess: true
            port: 3306
            migrations: true



  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - ./persistence/test/mysql:/var/lib/mysql
  redis:
    image: redis:5-alpine
    command: redis-server
    ports:
      - 6379:6379
    volumes:
      - ./persistence/test/redis:/data
    hostname: redis
    restart: always
    # env_file: ${ENV_FILE}

Ashik
  • 2,888
  • 8
  • 28
  • 53
  • **See Also**: [Docker Compose wait for container X before starting Y](https://stackoverflow.com/q/31746182/1366033) – KyleMit Nov 19 '20 at 23:14

1 Answers1

1

If you want to use the wait-for-it.sh to wait for the service mysql:3036 to become available, you will have to build your own image FROM prismagraphql/prisma:1.34.8 and COPY wait-for-it.sh to that image. After that you will have to create a custom startup script, which will call wait-for-fit.sh and then exec the main prisma process.

e.g. Dockerfile

FROM prismagraphql/prisma:1.34.8
COPY wait-for-it.sh /
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

e.g. entrypoint.sh

#!/usr/bin/env bash
/wait-for-it.sh mysql:3036   #add timeout if you want `-t 10s`
exec /app/start.sh "$@"

The tricky part is finding out the starting script inside images. Sometimes you will find a public Dockerfile in the projects repo or you will have to inspect the image e.g. docker image inspect prismagraphql/prisma:1.34.8 --format '{{.ContainerConfig.Entrypoint}}'

invad0r
  • 908
  • 1
  • 7
  • 20