脚本完成后,如何运行docker容器并提交更改? [英] How can I run a docker container and commit the changes once a script completes?

查看:132
本文介绍了脚本完成后,如何运行docker容器并提交更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个cron作业,以在docker容器内运行一组命令,然后将更改提交到docker映像。我可以将容器作为守护程序运行,并使用以下命令获取容器ID:

I want to set up a cron job to run a set of commands inside a docker container and then commit the changes to the docker image. I'm able to run the container as a daemon and get the container ID using this command:

CONTAINER_ID = $(sudo docker run -d my-image / bin / sh -c sleep 10)

但是我在第二部分遇到了麻烦-提交 sleep 10 命令完成后,将更改图像。我有办法告诉码头集装箱何时要被杀死并在运行之前运行另一个命令吗?

but I'm having trouble with the second part--committing the changes to the image once the sleep 10 command completes. Is there a way for me to tell when the docker container is about to be killed and run another command before it is?

编辑:作为替代,是否有办法通过容器中的shell脚本触发 ctrl-pq 来使容器运行但返回主机?

As an alternative, is there a way to trigger ctrl-p-q via a shell script in the container to leave the container running but return to the host?

推荐答案

在前台而不是作为守护程序运行它。当结束启动脚本时,它将控制并提交/推送

Run it in the foreground, not as daemon. When it ends the script that launched it takes control and commits/push it

这篇关于脚本完成后,如何运行docker容器并提交更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆