这个问题已经在这里有了答案: > Docker container will automatically stop after “docker run -d” 11个
为什么我的docker执行完我的shell脚本后退出?谢谢.
Docker版本:
docker --version
Docker version 1.12.4,build 1564f02
我的图片:
docker pull lw96/ubuntu-16.04-lnmp1.3
运行后:
docker run -it -d --name test -p 8080:80 lw96/ubuntu-16.04-lnmp1.3 sh /root/run.sh
我检查了:docker ps -a
root@ubuntu:/home/liwei# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68c0ce4c59f7 a57b0c1a60cf "/bin/bash" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp test
这是run.sh:
#! /bin/bash
lnmp restart
echo "lnmp already start"
exit 0
我有日志:
root@ubuntu:/home/liwei# docker logs -f test
+-------------------------------------------+
| Manager for LNMP,Written by Licess |
+-------------------------------------------+
| http://lnmp.org |
+-------------------------------------------+
Stoping LNMP...
Stoping Nginx... Nginx is not running.
* MysqL server PID file could not be found!
Gracefully shutting down PHP-fpm /etc/init.d/PHP-fpm: 82: kill: No such process
................................... Failed. Use force-quit
Starting LNMP...
Starting Nginx... done
Starting MysqL
.. *
Starting PHP-fpm done
lnmp already start!
之后,我的DOCKER集装箱出口:
root@ubuntu:/home/liwei# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb98d7427802 lw96/ubuntu-16.04-lnmp1.3 "sh /root/run.sh" 8 minutes ago Exited (0) 7 minutes ago test
但是,当我使用时:
docker pull lw96/ubuntu-16.04-lnmp1.3
docker run -it -d -p 80:80 --name test lw96/ubuntu-16.04-lnmp1.3
docker exec -it test /bin/bash
cd ~ && ./run.sh
我的容器运作良好.为什么?????
最佳答案