skip to Main Content

I am using Lumen with Docker to create simple API for authentication. After installing LumenPassport, I cannot migrate the database. I can easily connect to the MySQL db with Dbeaver.
I have already created one Lumen Docker project for the same purpose, it is the second. The first one worked without a problem. Moreover, I have checked the MySQL databases, ms_api_shop was there

Errors: enter image description here

Here is my docker-compose


services:
  nginx:
    build:
      context: .
      dockerfile: docker/Nginx.Dockerfile
    image: nginx
    ports:
      - 8092:80
    depends_on:
      - fpm
    volumes:
      - ./:/var/www/lumen-docker
    links:
      - mysql

  fpm:
    build:
      context: .
      dockerfile: docker/fpm.Dockerfile
    volumes:
      - ./:/var/www/lumen-docker
    depends_on:
      - mysql
    links:
      - mysql


  mysql:
    image: mysql:5.7
    ports:
      - 33006:3306
    environment:
      - MYSQL_ROOT_PASSWORD=
      - MYSQL_DATABASE=ms_api_shop
      - MYSQL_ROOT_USER=
    volumes:
      - mysql-data:/var/lib/mysql
volumes:
  mysql-data:


And env:

DB_HOST=mysql
DB_PORT=33006
DB_DATABASE=ms_api_shop
DB_USERNAME=
DB_PASSWORD=

3

Answers


  1. In your docker-file, you are binding the 33006 container port to the 3306 of the host port. In case you want to access the MySQL, you should use 3306 not 33006 as you did in your .env

    Login or Signup to reply.
  2. I have a Laravel app running in Docker and a part of my docker config looks like:

    But I personally feel that they should be within a docker network, look at the last two lines of the code in my docker-compose.yml below:

    mysql:
        image: mysql:5.7.29
        container_name: mysql
        restart: unless-stopped
        tty: true
        ports:
          - "3306:3306"
        environment:
          MYSQL_DATABASE: homestead
          MYSQL_USER: homestead
          MYSQL_PASSWORD: secret
          MYSQL_ROOT_PASSWORD: secret
          SERVICE_TAGS: dev
          SERVICE_NAME: mysql
        volumes:
          - ./mysql:/var/lib/mysql
        networks:
          - laravel    
    
    Login or Signup to reply.
  3. According to my knowledge, docker containers can communicate with each other when they are on the same network. You seem to have not connected these two docker in docker-compose yet. To get network information from a container, you can use the below command.

    $ docker inspect --format='{{json .NetworkSettings.Networks}}'  <docker_container_name>
    

    In case you need to connect these two containers, follow these steps:

    First, you create a network

    $ docker network create my-net
    

    Second, you connect container to the network.

    $ docker network connect my-net <docker_container_name>
    

    Don’t forget to connect these two containers to the network.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search