docker-compose up -d 运行容器秒自动停止解决方案

正常的我们运行Docker-Compose的服务

docker-compose -f docker-compose.yml up -d  mysql-setup 

执行Docker ps 查看存活的容器
Docker PS发现没失败但是未找到存活的容器

image

查看日志

docker logs mysql-setup


发现并没有报错。。。。

检查DockerFile

# Default override to use MySQL as a backing store for datahub-gms (same as docker-compose.mysql.yml).
---
version: '3.9'
services:
  mysql-setup:
    container_name: mysql-setup
    hostname: mysql-setup
    image: ${DATAHUB_MYSQL_SETUP_IMAGE:-acryldata/datahub-mysql-setup}:${DATAHUB_VERSION:-head}
    build:
      context: ../
      dockerfile: docker/mysql-setup/Dockerfile
    env_file: mysql-setup/env/docker.env
    depends_on:
      mysql:
        condition: service_healthy
    labels:
      datahub_setup_job: true
  mysql:
    container_name: mysql
    hostname: mysql
    image: mysql:${DATAHUB_MYSQL_VERSION:-5.7}
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --default-authentication-plugin=mysql_native_password
    ports:
    - ${DATAHUB_MAPPED_MYSQL_PORT:-3306}:3306
    env_file: mysql/env/docker.env
    restart: on-failure
    healthcheck:
      test: mysqladmin ping -h mysql -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
      start_period: 10s
      interval: 1s
      retries: 3
      timeout: 5s
    volumes:
    - ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
    - mysqldata:/var/lib/mysql
volumes:
  mysqldata:

解决方案

还需要挂在三个命令即可: command: /bin/bash tty: true stdin_open: true

  mysql-setup:
    container_name: mysql-setup
    hostname: mysql-setup
    image: ${DATAHUB_MYSQL_SETUP_IMAGE:-acryldata/datahub-mysql-setup}:${DATAHUB_VERSION:-head}
    command: /bin/bash
    build:
      context: ../
      dockerfile: docker/mysql-setup/Dockerfile
    env_file: ./mysql-setup/env/docker.env
    depends_on:
      mysql:
        condition: service_healthy
    labels:
      datahub_setup_job: true
    tty: true 
    stdin_open: true

再次启动成功

image

posted on 2023-12-15 18:21  白嫖老郭  阅读(867)  评论(0编辑  收藏  举报

导航