我想创建一个交互式容器,但也要在后台运行一个守护进程。
我使用ENTRYPOINT构建了一个图像(Dockerfile:ENTRYPOINT [" service"," mysql"," start"])并通过此图像,我创建了一个交互式容器,但容器只是没有启动..
$ docker create --net=host --name=debian-mysql -it ivanlmj/debian-7-mysql-5.7.12:latest bash a66630403170f87ca7760a4609675708fa98abfe7e2b7b53a76a147f626aa733 $ docker ps --all -f "name=debian-mysql" CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a66630403170 ivanlmj/debian-7-mysql-5.7.12:latest "service mysql start 14 seconds ago debian-mysql $ docker start debian-mysql debian-mysql $ docker ps --all -f "name=debian-mysql" CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a66630403170 ivanlmj/debian-7-mysql-5.7.12:latest "service mysql start 27 seconds ago Exited (0) Less than a second ago debian-mysql
构建交互式容器的正确方法是什么,该容器还有一个守护程序在后台自动运行?
非常感谢任何帮助。
先谢谢你们!
答案 0 :(得分:-1)
经过几个小时的努力,我找到了它!
Dockerfile内部:
FROM debian:jessie MAINTAINER Ivan Leon (ivanlmj@gmail.com) - @ivanleoncz RUN ... ... ... CMD service mysql start && bash
docker run --net=host --name=debian-mysql -it ivanlmj/debian-7-mysql-5.7.12
完成!
重要信息
CMD has two forms: with shell and without shell (JSON Array). If you use the shell form of the CMD, then the will execute in "/bin/sh -c" (it is the default Docker ENTRYPOINT).