skip to Main Content

I have a Next js application that I’m trying to dockerize. It shows an error while migrating Prisma. It uses MySQL as a base

docker-compose.yml

version: '3.8'

services:
  mysql:
    container_name: discord-mysql
    restart: unless-stopped
    image: mysql:8.0.26
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: 12345
    ports:
      - "3307:3306"
    volumes:
      - ./mysql_data:/var/lib/mysql/data
    networks:
      - shared-network

  frontend:
    container_name: discord-frontend
    restart: unless-stopped
    build:
      context: .
      dockerfile: Dockerfile
      target: development
    ports:
      - "3000:3000"
    depends_on:
      - mysql
    networks:
      - shared-network

networks:
  shared-network:

Dockerfile is

FROM node:18 as development

WORKDIR /usr/app

COPY package*.json .

RUN npm install -g pnpm

RUN pnpm install

COPY . .

RUN npx prisma generate

EXPOSE 3000
EXPOSE 3306

CMD ["sh", "-c", "npx prisma migrate deploy && pnpm run dev"]

when i run docker-compose up it shows the following error

discord-mysql     | 2023-12-31 21:31:03+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
discord-mysql     | 2023-12-31 21:31:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
discord-mysql     | 2023-12-31 21:31:03+00:00 [Note] [Entrypoint]: Initializing database files
discord-mysql     | 2023-12-31T21:31:03.393906Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.26) initializing of server in progress as process 42
discord-mysql     | 2023-12-31T21:31:03.395199Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
discord-mysql     | 2023-12-31T21:31:03.395206Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
discord-mysql     | 2023-12-31T21:31:03.395269Z 0 [ERROR] [MY-010119] [Server] Aborting
discord-mysql     | 2023-12-31T21:31:03.395427Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.26)  MySQL Community Server - GPL.

ignore the following:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras porttitor nisl et volutpat rhoncus. Quisque ut ante vitae arcu luctus fringilla et vitae enim. Nullam maximus ipsum vitae orci pharetra commodo. Aliquam interdum blandit arcu et vestibulum. Morbi sapien risus, suscipit id faucibus id, malesuada eu mauris. Mauris varius, ipsum quis suscipit gravida, neque est interdum lacus, ut tempus elit erat a tortor. Vestibulum eu efficitur eros. Pellentesque non lorem non ligula bibendum blandit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque laoreet risus nec lacus blandit iaculis.

2

Answers


  1. the problem with volume path:

    volumes:
        - ./mysql_data:/var/lib/mysql/data
    

    It says that data folder is not empty.
    I think data folder is used before by another docker container that’s why it is not empty.

    Use this command docker system prune --volumes.

    Also try changing data directory if problem still there.

    volumes:
        - ./mysql_data:/var/lib/mysql/storage
    
    Login or Signup to reply.
  2. Your problem is that You pointed /var/lib/mysql/data,

    but data dir is: /var/lib/mysql, that’s why /var/lib/mysql which is being created is different.

    fix mount point: - ./mysql_data:/var/lib/mysql/data

    make sure ./mysql_data is empty, then start docker.

    next time it will not be different.

    version: '3.8'
    
    services:
      mysql:
        container_name: discord-mysql
        restart: unless-stopped
        image: mysql:8.0.26
        command: --default-authentication-plugin=mysql_native_password
        environment:
          MYSQL_ROOT_PASSWORD: 12345
        ports:
          - "3307:3306"
        volumes:
          - ./mysql_data:/var/lib/mysql
        networks:
          - shared-network
    
      frontend:
        container_name: discord-frontend
        restart: unless-stopped
        build:
          context: .
          dockerfile: Dockerfile
          target: development
        ports:
          - "3000:3000"
        depends_on:
          - mysql
        networks:
          - shared-network
    
    networks:
      shared-network:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search