How can I run docker container without entering into container

[亡魂溺海] 提交于 2021-02-07 08:15:33

问题


I have Dockefile

FROM centos:7

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

sudo docker build -t my_container .

Then I start it.

sudo docker run -t my_container

And I get open tty to container

root@my_container_id/

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


回答1:


You can start your container in a detached mode:

docker run -it -d my_container

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

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

docker exec -it my_container /bin/sh 



回答2:


You can't do that. Your container lives if its main process is running, so you have to have a main process which is the process with PID 1 inside your container, and your container will be up if that process is running.



来源:https://stackoverflow.com/questions/43493478/how-can-i-run-docker-container-without-entering-into-container

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!