Docker test DB does not start

Overview

For some reason, I was addicted to the phenomenon that Docker's test DB ended in Exit 1, so I made a note.

src $ docker-compose ps
         Name                     Command           State            Ports
-----------------------------------------------------------------------------------
db                        docker-entrypoint.sh      Up       0.0.0.0:3307->3306/tcp
                          mysqld                             , 33060/tcp
db-testing                docker-entrypoint.sh      Exit 1
                          mysqld
docker-laravel_app_1      docker-php-entrypoint     Up       0.0.0.0:18000->8000/tc
                          php-fpm                            p, 9000/tcp
docker-laravel_https-     /init                     Exit 0
portal_1
docker-laravel_web_1      nginx -g daemon off;      Up       0.0.0.0:10080->80/tcp

environment

MacBook Air 2019 (core-i5, RAM16GB) Laravel7 Docker for Desktop 2.3.0.4 Docker version 19.03.12 Docker-compose version 1.26.2

Applicable Docker-compose.yml

docker-compose.yml


version: "3"
services:

  db:
    build:
      context: ./docker/mysql
    container_name: db
    volumes:
      - db-store:/var/lib/mysql
      - db-logs-store:/var/log/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    environment:
      - MYSQL_DATABASE=${DB_NAME:-JETmysql}
      - MYSQL_USER=${DB_USERNAME:-root}
      - MYSQL_PASSWORD=${DB_PASS:-secret}
      - MYSQL_ROOT_PASSWORD=${DB_PASS:-secret}
      - TZ=${TZ:-Asia/Tokyo}
    ports:
      - ${DB_PORT}:3306

  db-testing:
    image: mysql:8.0
    container_name: db-testing
    volumes:
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    tmpfs:
      - /var/lib/mysql
      - /var/log/mysql
    environment:
      - MYSQL_DATABASE=${DB_NAME:-JETmysql}
      - MYSQL_USER=${DB_USERNAME:-root}
      - MYSQL_PASSWORD=${DB_PASS:-secret}
      - MYSQL_ROOT_PASSWORD=${DB_PASS:-secret}
      - TZ=${TZ:-Asia/Tokyo}
    ports:
      - ${DB_TESTING_PORT}:3306
 
volumes:
  db-logs-store:
  db-store:
  redis-store:

At first glance it seemed to be okay, but with this I couldn't write the log and got a permission error.

src $ docker logs db-testing
2020-09-05 16:31:21+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-09-05 16:31:22+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-09-05 16:31:22+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-09-05 16:31:22+09:00 [Note] [Entrypoint]: Initializing database files
2020-09-05T16:31:22.412681+09:00 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 43
2020-09-05T16:31:22.420005+09:00 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/mysql-error.log' for error logging: No such file or directory
2020-09-05T16:31:22.420889+09:00 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.
2020-09-05T16:31:22.421233+09:00 0 [ERROR] [MY-010119] [Server] Aborting
2020-09-05T16:31:22.421572+09:00 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21)  MySQL Community Server - GPL.

To avoid this, write the permission cmd in the Dockerfile.

FROM mysql:8.0
RUN mkdir /var/log/mysql
RUN chown mysql:mysql /var/log/mysql

Comment out the image and load the Dockerfile.

docker-compose.yml


db-testing:
    # image: mysql:8.0
    build:
      context: ./docker/mysql
      dockerfile: Dockerfile.test

I thought this would fix it, but another error occurred.

2020-09-05 16:37:43+09:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-09-05 16:37:53+09:00 [Note] [Entrypoint]: Creating database JETmysql
2020-09-05 16:37:53+09:00 [Note] [Entrypoint]: Creating user root
ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'

Can't make a USER because the time zone is wrong? ?? I thought, but I missed it.

Solved by not specifying USERNAME and tmpfs log

docker-compose.yml


db-testing:
    # image: mysql:8.0
    build:
      context: ./docker/mysql
      dockerfile: Dockerfile.test
    container_name: db-testing
    volumes:
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    tmpfs:
      - /var/lib/mysql
      # - /var/log/mysql
    environment:
      - MYSQL_DATABASE=${DB_NAME:-JETmysql}
      # - MYSQL_USER=${DB_USERNAME:-root}
      - MYSQL_PASSWORD=${DB_PASS:-secret}
      - MYSQL_ROOT_PASSWORD=${DB_PASS:-secret}
      - TZ=${TZ:-Asia/Tokyo}
    ports:
      - ${DB_TESTING_PORT}:3306

Warning is still issued. .. It started for the time being.

Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-09-05 16:45:50+09:00 [Note] [Entrypoint]: Creating database JETmysql

2020-09-05 16:45:50+09:00 [Note] [Entrypoint]: Stopping temporary server
2020-09-05 16:45:53+09:00 [Note] [Entrypoint]: Temporary server stopped

2020-09-05 16:45:53+09:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

According to the following, because you have already specified the root user somewhere If you specify it again, an error will occur. It's true that the db specifies it, but I don't understand the reason because the containers should not interfere with each other. .. https://github.com/docker-library/mysql/issues/129#issuecomment-178265632

If anyone knows, please let me know.

Recommended Posts

Docker test DB does not start
MySQL container does not start in Docker
Terminal does not start
Localhost3000 does not start up in Docker / Rails development.
Docker Compose does not start with docker.credentials.errors.InitializationError error message
Container does not start with docker-compose
If the DB container does not start with Initializing database files
Spring Boot 2.0.0 does not start built-in tomcat
[NetBeans] Story when it does not start
[Docker] Does not connect to MySQL workbench ... DB container port forwarding settings
Docker + Spring-boot start
Eclipse does not start after Java 11 is installed
Bundle install with docker + rails6 does not reflect gem
When Docker for Mac 2.4.0.0 does not reflect file changes
Sidekiq-limit_fetch does not work
When the server does not start with rails s
Docker for Windows: MySQL container does not start when migrating from Hyper-v to WSL2
What to check when rails db: migration does not pass
Docker does not work when DOCKER_HOST is specified in WSL2
How to get the log when install4j does not start
rails test db only drop
bundle install does not install mysql2
docker review image creation-container start
Ruby version does not switch
How to fix the problem that Aptana Studio does not start
What I did when the DB did not start with docker-compose up
Addressing an issue where cron-driven docker (docker-compose) exec does not run
WSL2 + Docker Desktop for Windows does not launch only MySQL container