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文件也是如此。如何防止退出?
答案 0 :(得分:0)
您需要以守护程序模式运行映像-这就是他们在官方MySQL映像中执行的操作:
ENTRYPOINT ["mysqld"]
在特定情况下,可以在入口点SH文件/mysql/setup.sh
的末尾运行“ mysqld”。
答案 1 :(得分:0)
为了在容器受限制时导入转储,您只需使用卷指令将其添加到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