应用程序停止后如何避免Docker容器停止说明 [英] How do avoid a docker container stop after the application is stopped description

查看:326
本文介绍了应用程序停止后如何避免Docker容器停止说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个带有Postgres服务器的Docker容器。 postgres已停止或崩溃(没关系),我需要检查一些环境变量和一些文件的状态。

There is a docker container with Postgres server. Ones postgres is stopped or crashed (doesn't matter) I need to check some environment variables and the state of a few files.

默认情况下,容器在申请完成。
我知道有一个选项可以更改dockerfile中的默认行为,但我不再找到它((
如果有人知道,请给我一个像这样的Dockerfile示例:

By default, the container stops after an application is finished. I know there is an option to change the default behavior in dockerfile but I no longer to find it (( If somebody knows that please give me an Dockerfile example like this :

FROM something

RUN something ...

ENTRYPOINT [something]


推荐答案

当主进程运行时,没有选项可以保持容器运行已停止或死亡。您可以在调试实际的启动脚本时在容器中运行其他操作。有时您需要覆盖入口点才能执行此操作。

There isn't an "option" to keep a container running when the main process has stopped or died. You can run something different in the container while debugging the actual startup scripts. Sometimes you need to override an entrypoint to do this.

docker run -ti $IMAGE /bin/sh
docker run -ti --entrypoint=/bin/sh $IMAGE

如果在 docker start 现有容器时主进程不会保持运行,则您将无法使用该进程容器交互,否则您可以:

If the main process will not stay running when you docker start the existing container then you won't be able to use that container interactively, otherwise you could:

docker start $CID
docker exec -ti $CID sh 

要从现有容器中获取文件,您可以 docker cp 停止的容器。

For getting files from an existing container, you can docker cp anything you need from the stopped container.

docker cp $CID:/a/path /some/local/path

您还可以 docker export 完整容器的tar存档。

You can also docker export a tar archive of the complete container.

docker export $CID -o $CID.tar
tar -tvf $CID.tar | grep afile

可以使用 docker inspect ,但这不会为您提供该过程添加到环境中的任何东西。

The environment Docker injects can be seen with docker inspect, but this won't give you anything the process has added to the environment.

docker inspect $CID --format '{{ json .Config.Env }}'

这篇关于应用程序停止后如何避免Docker容器停止说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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