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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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!