我如何在不进入容器的情况下运行Docker容器 [英] How can I run docker container without entering into container

查看:125
本文介绍了我如何在不进入容器的情况下运行Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Dockefile

I have Dockefile

FROM centos:7

所以我在dockerfile中没有入口点.然后将其构建为图像

So I have no entrypoint in dockerfile. Then I build it to image

sudo docker build -t my_container .

然后我开始.

sudo docker run -t my_container

然后我将tty打开到容器

And I get open tty to container

root@my_container_id/

如果我在没有 -t 的情况下启动它,则启动后立即停止.如何在没有启动tty且没有入口点的情况下运行docker容器?

If I start it without -t it stopped immidiately after start. How can I run docker container without start tty and without entrypoint?

推荐答案

您可以在 分离模式:

You can start your container in a detached mode:

docker run -it -d my_container

此处的 -d 选项意味着您的容器将在后台以分离"模式运行.

The -d option here means your container will run in "detached" mode, in the background.

如果您要附加容器并放到外壳上,您可以使用:

If you want to attach the container and drop to a shell, you can use:

docker exec -it my_container /bin/bash

请注意,如果您的容器基于高山图片,则需要使用 sh ,即:

Note, if your container is based on an alpine image, you need to use sh, i.e.:

docker exec -it my_container /bin/sh 

这篇关于我如何在不进入容器的情况下运行Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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