docker 启动镜像后执行 shell 命令

方式一:

在启动命令后面直接追加命令 /bin/bash -c

docker run -ti name/tmp /bin/bash -c "nohup Server 10090; python /data/Code/ARKITBuildMap/WebServer/simple_http_server.py 10080; sleep infinity"

方式二:

在docker中添加需要启动的服务脚本 service.sh (假定放在 /home 目录下)

#!/bin/sh

/bin/serviceA start #启动服务

/bin/bash #保留一个终端,防止容器自动退出

将容器打包为镜像

docker commit -m "Added service test" -a "Docker Newbee" 0b2616b0e5a8 ouruser/test:v1

启动新的镜像

docker run -ti ouruser/test:v1 /bin/bash /home/service.sh

猜你喜欢

转载自www.cnblogs.com/yxfcnbg/p/12650457.html