Question

MySQL Docker Image is always restarting status

I followed step by step this article ( https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose-on-ubuntu-20-04 ).

I just changed php version (8.1) instead of (7.4) and mysql version (8.0) instead of (5.7.22)

When I run (docker ps) command, digitalocean.com/php and nginx:alpine are fine. But mysql:8.0 is always restarting status.

But I tested firstly it in local development.

When local development, everything is okay.

Buy I deployed it in the droplet, I faced the error that MySQL is always restarting status.

When I run (docker logs -f <container id>) command, I faced the following error.

2022-08-13 06:35:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started. 2022-08-13 06:35:20+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’ 2022-08-13 06:35:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started. ‘/var/lib/mysql/mysql.sock’ -> ‘/var/run/mysqld/mysqld.sock’

When I run (docker run --restart=always mysql:8.0) command, I faced the following error.

2022-08-13 06:57:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started. 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. 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: - MYSQL_ROOT_PASSWORD - MYSQL_ALLOW_EMPTY_PASSWORD - MYSQL_RANDOM_ROOT_PASSWORD


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
August 15, 2022

Hi @lovableazurescubadiver,

According to the error and to the documentation, you need to specify the MYSQL_ROOT_PASSWORD with the use of - and = and also you should use a ‘password’ The result it will be:

  • MYSQL_ROOT_PASSWORD=some_password

Alternatively, you can add it to your environment file:

version: '2' 
  services:
   db:
    image: mysql
    volumes:
      - "./sito/db/:/var/lib/mysql"
    ports:
      - "3306:3306"
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=some_password

If you wish to use blank/empty password then use the following:

MYSQL_ALLOW_EMPTY_PASSWORD=1

If you wish to set a random password then use the following:

MYSQL_RANDOM_ROOT_PASSWORD=1

Hope that helps!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel