docker stack mysql service start then stop again

Viewed 349

I have an issue with mysql service it started then stopped when i deploy the stack. I am not really sure what is wrong. There are no errors on the logs. It works fine on docker-compose I am not sure why it keep shutting down when i deploy it. From the error log i am getting this in line 191: 47 Killed "$@" --initialize-insecure --default-time-zone=SYSTEM can this be the source of the problem? I am using this version of mysql mysql official image

services:
  db: 
    image: mysql
    #container_name: mysql_db
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    secrets:
      - mysql_root_password
      - mysql_database
      - mysql_user
      - mysql_password
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
      MYSQL_DATABASE_FILE: /run/secrets/mysql_database
      MYSQL_USER_FILE: /run/secrets/mysql_user
      MYSQL_PASSWORD_FILE: /run/secrets/mysql_password
    ports:
      - "9906:3306"
 
    networks:
      - back-tier

    volumes:
      - alpine-db_backup:/var/lib/mysql
      - alpine-mysql_logs:/var/log/mysql
      - alpine-mysql_cnf:/etc/mysql
    deploy:
      replicas: 3
      restart_policy:
        condition: on-failure
        delay: 30s
        max_attempts: 10
        window: 60s
      update_config:
        parallelism: 1
        delay: 10s
        max_failure_ratio: 0.3
      resources:
        limits:
          cpus: '0.50'
          memory: 90M
        reservations:
          cpus: '0.25'
          memory: 50M
       

networks:
    front-tier:
      driver: overlay
    back-tier:
      driver: overlay

Error Logs

client_db.1.vvhd3rxc245e@worker-1    | 2021-12-02 04:45:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.1.vvhd3rxc245e@worker-1    | 2021-12-02 04:45:01+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.1.vvhd3rxc245e@worker-1    | 2021-12-02 04:45:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.88e3qb36ensi@worker-1    | 2021-12-02 04:44:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.88e3qb36ensi@worker-1    | 2021-12-02 04:44:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.2.88e3qb36ensi@worker-1    | 2021-12-02 04:44:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.1.x4976pxrrumi@worker-2    | 2021-12-02 04:43:57+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.1.x4976pxrrumi@worker-2    | 2021-12-02 04:43:57+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.1.x4976pxrrumi@worker-2    | 2021-12-02 04:43:57+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.my3k6agifuun@worker-2    | 2021-12-02 04:44:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.my3k6agifuun@worker-2    | 2021-12-02 04:44:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.3.my3k6agifuun@worker-2    | 2021-12-02 04:44:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.yu9cgxx0jn1b@worker-2    | 2021-12-02 04:43:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.yu9cgxx0jn1b@worker-2    | 2021-12-02 04:43:36+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.3.yu9cgxx0jn1b@worker-2    | 2021-12-02 04:43:36+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.y2pd68ny9yn5@worker-2    | 2021-12-02 04:44:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.y2pd68ny9yn5@worker-2    | 2021-12-02 04:44:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.2.y2pd68ny9yn5@worker-2    | 2021-12-02 04:44:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Initializing database files
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:40.858385Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:40.858893Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 45
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:40.870822Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:44.274928Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
client_db.2.tx9luw14iylo@worker-2    | /usr/local/bin/docker-entrypoint.sh: line 191:    45 Killed                  "$@" --initialize-insecure --default-time-zone=SYSTEM

1 Answers

it turns out i wasn't making the mysql service persistent in my stack application which was causing the mysql container to keep shutting down when i deploy the stack. So i made the mysql service persistent by setting the constraint to run on the Manager node because i had create the volume on the manager node and then map the node to the container so that the container can have persistent data. This solve the solve the issue.

db: 
    image: mysql
    #container_name: mysql_db
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    secrets:
      - mysql_root_password
      - mysql_database
      - mysql_user
      - mysql_password
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
      MYSQL_DATABASE_FILE: /run/secrets/mysql_database
      MYSQL_USER_FILE: /run/secrets/mysql_user
      MYSQL_PASSWORD_FILE: /run/secrets/mysql_password
    ports:
      - "9906:3306"
 
    networks:
      - back-tier

    volumes:
      - alpine-db_backup:/var/lib/mysql
      - alpine-mysql_logs:/var/log/mysql
      - alpine-mysql_cnf:/etc/mysql
    deploy:
      replicas: 3
      placement:
        constraints: [node.role == manager]
      resources:
        reservations:
          memory: 128M
        limits:
          memory: 256M
      restart_policy:
        condition: on-failure
        delay: 30s
        max_attempts: 10
        window: 60s
      update_config:
        parallelism: 1
        delay: 10s
        max_failure_ratio: 0.3
      

Related