防止脚本在docker容器中退出

2skhul33  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(302)

shell脚本:


# !/bin/sh

service mysql start
mysql < /mysql/dockerSql.sql
service mysql stop

docker文件:

FROM mysql:5.6
ADD setup.sh /mysql/setup.sh
ADD dockerSql.sql /mysql/dockerSql.sql
ENTRYPOINT ["sh", "/mysql/setup.sh"]

docker编写文件:

version: '3'

services:  
  nariadi-front:
    container_name: nariadi_frontend_container
    build: ./NariadiFrontEndDocker
    ports: 
        - "5002:80"
    depends_on:
        - nariadi-service

  nariadi-service:
    container_name: nariadi_backend_container
    build: ./Nariadi
    ports: 
        - "5008:5008"
    depends_on: 
        - mysql-docker-nariadi
    #command: python manage.py loaddata -t nariadi_docker -u admin

  mysql-docker-nariadi:
    build: ./docker-mysql
    ports:
        - "3310:3306"
    tty: true
    #command: --default-authentication-plugin=mysql_native_password

答复:

mysql-docker-nariadi_1  | No directory, logging in with HOME=/
mysql-docker-nariadi_1  | ..
mysql-docker-nariadi_1  | [info] MySQL Community Server 5.6.40 is started.
mysql-docker-nariadi_1  | ...
mysql-docker-nariadi_1  | [info] MySQL Community Server 5.6.40 is stopped.
mysql-docker-nariadi_1  | ------_DONEEEEEEEEEEE_------------
nariadi_backend_container | [2018-08-09 10:42:52 +0000] [1] [INFO] Starting gunicorn 19.7.1
nariadi_backend_container | [2018-08-09 10:42:52 +0000] [1] [INFO] Listening at: http://0.0.0.0:5008 (1)
nariadi_backend_container | [2018-08-09 10:42:52 +0000] [1] [INFO] Using worker: sync
nariadi_backend_container | [2018-08-09 10:42:52 +0000] [8] [INFO] Booting worker with pid: 8
nariadi_backend_container | [2018-08-09 10:42:52 +0000] [10] [INFO] Booting worker with pid: 10
nariadi_backend_container | [2018-08-09 10:42:52 +0000] [11] [INFO] Booting worker with pid: 11
nariadi_backend_container | [2018-08-09 10:42:53 +0000] [12] [INFO] Booting worker with pid: 12
nariadi_frontend_container | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.18.0.2. Set the 'ServerName' directive globally to suppress this message
nariadi_frontend_container | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.18.0.2. Set the 'ServerName' directive globally to suppress this message
nariadi_frontend_container | [Thu Aug 09 10:42:54.528127 2018] [mpm_event:notice] [pid 1:tid 140035064244096] AH00489: Apache/2.4.33 (Unix) configured -- resuming normal operations
nariadi_frontend_container | [Thu Aug 09 10:42:54.528422 2018] [core:notice] [pid 1:tid 140035064244096] AH00094: Command line: 'httpd -D FOREGROUND'
desktop_mysql-docker-nariadi_1 exited with code 0

当我运行docker compose up时,mysql docker nariadi服务存在,代码为0。shell脚本正在执行,并且.sql文件也在执行。如何防止退出?

zbwhf8kr

zbwhf8kr1#

为了在容器启动时导入转储,您只需使用卷指令将其添加到docker compose文件:

volumes:
  - ./dump.sql:/docker-entrypoint-initdb.d/dump.sql

不需要使用 ENTRYPOINT . 它应该看起来:

mysql-docker-nariadi:
    image: mysql:5.6
    ports:
        - "3310:3306"
    volumes:
      - ./dump.sql:/docker-entrypoint-initdb.d/dump.sql
q0qdq0h2

q0qdq0h22#

您需要在守护程序模式下运行映像—这就是他们在官方mysql映像中的操作方式:

ENTRYPOINT ["mysqld"]

在您的特定情况下,可以在entrypoint sh文件的末尾运行“mysqld” /mysql/setup.sh .

相关问题