title: MySQL Docker Image is always restarting status
body: <p>I followed step by step this article ( <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose-on-ubuntu-20-04" rel="nofollow noreferrer">https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose-on-ubuntu-20-04</a> ).</p>
  <p>I just changed php version (8.1) instead of (7.4) and mysql version (8.0) instead of (5.7.22)</p>
  <p>When I run (docker ps) command, digitalocean.com/php and nginx:alpine are fine. But mysql:8.0 is always restarting status.</p>
  <p>But I tested firstly it in local development.</p>
  <p>When local development, everything is okay.</p>
  <p>Buy I deployed it in the droplet, I faced the error that MySQL is always restarting status.</p>
  <p>When I run (docker logs -f ) command, I faced the following error.</p>
  <ul>
  <li>2022-08-13 06:35:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.</li>
  <li>2022-08-13 06:35:20+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’</li>
  <li>2022-08-13 06:35:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.</li>
  <li>‘/var/lib/mysql/mysql.sock’ -&gt; ‘/var/run/mysqld/mysqld.sock’</li>
  </ul>
  <p>When I run (docker run --restart=always mysql:8.0) command, I faced the following error.</p>
  <ul>
  <li>2022-08-13 06:57:37+00:00 [Note] [Entrypoint]: Entrypoint script - for MySQL Server 8.0.30-1.el8 started.</li>
  <li>2022-08-13 06:57:38+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’ 2022-08-13 06:57:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.</li>
  <li>2022-08-13 06:57:38+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
  You need to specify one of the following:</li>
  <li>MYSQL_ROOT_PASSWORD</li>
  <li>MYSQL_ALLOW_EMPTY_PASSWORD</li>
  <li>MYSQL_RANDOM_ROOT_PASSWORD</li>
  </ul>
  <p>Dockerfile</p>
  <pre><code>FROM php:8.1-fpm
  
  # Copy composer.lock and composer.json
  COPY composer.lock composer.json /var/www/
  
  # Set working directory
  WORKDIR /var/www
  
  # Install dependencies
  RUN apt-get update &amp;&amp; apt-get install -y \
      build-essential \
      libpng-dev \
      libjpeg62-turbo-dev \
      libfreetype6-dev \
      locales \
      zip \
      jpegoptim optipng pngquant gifsicle \
      vim \
      unzip \
      git \
      curl \
      libzip-dev
  
  # Clear cache
  RUN apt-get clean &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  # Install composer
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  
  # Add user for laravel application
  RUN groupadd -g 1000 www
  RUN useradd -u 1000 -ms /bin/bash -g www www
  
  # Copy existing application directory contents
  COPY . /var/www
  
  # Copy existing application directory permissions
  COPY --chown=www:www . /var/www
  
  # Change current user to www
  USER www
  
  # Expose port 9000 and start php-fpm server
  EXPOSE 9000
  CMD [&quot;php-fpm&quot;]
  </code></pre>
  <p>docker-compose.yml</p>
  <pre><code>version: '3'
  services:
    
    #PHP Service
    app:
      build:
        context: .
        dockerfile: Dockerfile
      image: digitalocean.com/php
      container_name: app
      restart: unless-stopped
      tty: true
      environment:
        SERVICE_NAME: app
        SERVICE_TAGS: dev
      working_dir: /var/www
      volumes:
        - ./:/var/www
        - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
      networks:
        - app-network
  
    #Nginx Service
    webserver:
      image: nginx:alpine
      container_name: webserver
      restart: unless-stopped
      tty: true
      ports:
        - &quot;80:80&quot;
        - &quot;443:443&quot;
      volumes:
        - ./:/var/www
        - ./nginx/conf.d/:/etc/nginx/conf.d/
      networks:
        - app-network
  
    #MySQL Service
    db:
      image: mysql:8.0
      container_name: db
      restart: unless-stopped
      tty: true
      ports:
        - &quot;3306:3306&quot;
      environment:
        MYSQL_DATABASE: laravel
        MYSQL_ROOT_PASSWORD: 123123
        SERVICE_TAGS: dev
        SERVICE_NAME: mysql
      volumes:
        - dbdata:/var/lib/mysql/
        - ./mysql/my.cnf:/etc/mysql/my.cnf
      networks:
        - app-network
  
  #Docker Networks
  networks:
    app-network:
      driver: bridge
  #Volumes
  volumes:
    dbdata:
      driver: local
  </code></pre>