Dockerize Prisma App


#1

Hey !

I just finished to dockerize my app. I think that can be useful so I share it with you. Please feel free to comment if my docker conf could be improved :slight_smile:

docker-compose.yml

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.16.2
    restart: always
    ports:
      - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        managementApiSecret: XXX
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: XXX
            migrations: true
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: XXX
    volumes:
      - mysql:/var/lib/mysql
    ports:
      - "3306:3306"
  web:
    build: .
    restart: always
    ports:
      - "4000:4000"
    depends_on:
      - "prisma"
    command: ./wait-for-it.sh prisma:4466 -- bash -c "prisma deploy && npm start"
    environment:
      PRISMA_ENDPOINT: http://prisma:4466
      PRISMA_SECRET: XXX
      APP_SECRET: XXX

volumes:
  mysql:

Dockerfile

FROM node:8.10
WORKDIR /code
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4000

I forced prima to use 4000 port :

server.start({ port: 4000 }, ({ port }) => winston.info(
    `Server started, listening on port ${port} for incoming requests. Watch it !`,
  ));

And here

db: new Prisma({
        endpoint:  'http://prisma:4466', //  you have to use prisma: instead of localhost: in docker env
...
      }),

If you want to develop on your docker, just replace npm start by nodemon for example in the docker-compose.yml and use this trick on mac http://www.fredlackey.com/develop-on-docker-without-slow-dependencies/ to develop without wait a long time at each refresh.

Hope that helps ! :stuck_out_tongue:


#2

My schema:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.15
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: prisma
            migrations: true
            rawAccess: false
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      # Can set another path 
      - mysql:/var/lib/mysql
    networks:
      default:
        ipv4_address: 172.30.0.20
volumes:
  mysql:

networks:
  default:
    driver: bridge
    ipam:
     config:
       - subnet: 172.30.0.0/16

Here i set static ip for mysql container and even after server reboot ip do not changed. In this case i can add in /etc/hosts, for example 172.30.0.20 prisma.mysql and connect directly mysql -h prisma.mysql


#3

@fabien.demaestri were you able to run prisma deploy?

I am attempting something similar. I have been able to get the docker containers up and communicating. However, running prisma deploy from within my prisma folder yields:

Could not connect to server at http://prisma:4466. Please check if your server is running.

If I run prisma deploy with http://localhost:4466 it works fine. However, I end up having to change the endpoint back to ‘http://prisma:4466’ to run prisma generate. I think it is something to do with the container network that is created although I haven’t quite figured it out yet…


#4
version: '3'
services:
  prisma:
image: prismagraphql/prisma:1.18
restart: always
ports:
- "4466:4466"
environment:
  PRISMA_CONFIG: |
    port: 4466
    # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
    # managementApiSecret: my-secret
    databases:
      default:
        connector: postgres
        host: postgres
        port: 5432
        user: prisma
        password: prisma
        database: NameMyDatabase
        migrations: true
        rawAccess: true
  postgres:
image: postgres
restart: "unless-stopped"
hostname: postgres
environment:
  POSTGRES_USER: prisma
  POSTGRES_PASSWORD: prisma
  PG_DATA: /data/postgres
volumes:
  - postgres:/var/lib/postgresql/data
  pgadmin:
image: dpage/pgadmin4
restart: "unless-stopped"
environment:
  PGADMIN_DEFAULT_EMAIL: admin@admin.com
  PGADMIN_DEFAULT_PASSWORD: admin
volumes:
  - pgadmin:/root/.pgadmin
ports:
  - "5050:80"
depends_on:
  - postgres
volumes:
  ? postgres
  ? pgadmin

#5

I’m getting the same error.

Could not connect to server at http://prisma:4466. Please check if your server is running.