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
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
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.
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