Prisma1: Cannot connect Prisma to a local MySQL container on a different port than 3306

Created on 20 Sep 2018  路  1Comment  路  Source: prisma/prisma1

Describe the bug
Connecting Prisma to a local MySQL docker container on a different port than 3306 crashes Prisma.

To Reproduce
Steps to reproduce the behavior:

  1. npm install prisma@beta
  2. prisma init abc -> follow wizard to create new docker-compose.yml for local MySQL
  3. cd abc
  4. replace docker-compose.yml with
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.17-beta
    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: 3307
            user: root
            password: prisma
            migrations: true
            rawAccess: true
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    ports:
+      - "3307:3306"
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql:
  • run docker-compose up -d
  • periodically run docker ps and check the status of the prisma container - it'll restart every ~10 seconds and crash:

image

Expected behavior
Prisma connects to the MySQL container on port 3307.

Versions (please complete the following information):

  • OS: OS X
  • prisma CLI: prisma/1.17.0-beta.24 (darwin-x64) node-v10.8.0
  • Prisma Server: 1.17-beta
bu2-confirmed areengine

Most helpful comment

I looked into this and concluded that this is not a bug but a misunderstanding about docker-compose. I also misunderstood it and just realised after a few minutes as it is easy to fall for this.
The important thing is this port mapping of the mysql container:

ports:
  - "3307:3306"

This line maps the container port 3306 to the port 3307 on the host system. That means one can reach the mysql instance on this port when using something like a GUI. However this does not change the port of the mysql container inside the docker network. The prisma instance must still use the port 3306 the MySQL container is exposing.
In order to get it to work one would have to start the MySQL server with a different port in the first place. Usually popular Docker images expose environment variables to do so but i could not find them for MySQL. Instead It seems like MySQL can only be configured through config files that are a lot more cumbersome in conjunction with Docker.

TLDR: It's not a bug. This configuration does not run MySQL on port 3307 inside the docker network and therefore it does not work.

>All comments

I looked into this and concluded that this is not a bug but a misunderstanding about docker-compose. I also misunderstood it and just realised after a few minutes as it is easy to fall for this.
The important thing is this port mapping of the mysql container:

ports:
  - "3307:3306"

This line maps the container port 3306 to the port 3307 on the host system. That means one can reach the mysql instance on this port when using something like a GUI. However this does not change the port of the mysql container inside the docker network. The prisma instance must still use the port 3306 the MySQL container is exposing.
In order to get it to work one would have to start the MySQL server with a different port in the first place. Usually popular Docker images expose environment variables to do so but i could not find them for MySQL. Instead It seems like MySQL can only be configured through config files that are a lot more cumbersome in conjunction with Docker.

TLDR: It's not a bug. This configuration does not run MySQL on port 3307 inside the docker network and therefore it does not work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schickling picture schickling  路  3Comments

marktani picture marktani  路  3Comments

nikolasburk picture nikolasburk  路  3Comments

dohomi picture dohomi  路  3Comments

sorenbs picture sorenbs  路  3Comments