Docker容器不启动(码头启动) [英] Docker container not starting (docker start)

查看:3718
本文介绍了Docker容器不启动(码头启动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令创建了容器:

I created the container with the following command:

docker run -d -p 52022:22 basickarl/docker-git-test

这是命令:

root@basickarl:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
root@basickarl:~# docker ps -a
CONTAINER ID        IMAGE                              COMMAND             CREATED             STATUS                           PORTS               NAMES
e4ac54468455        basickarl/docker-git-test:latest   "/bin/bash"         7 minutes ago       Exited (0) 26 seconds ago                            adoring_lumiere     
22d7c5d83871        basickarl/docker-git-test:latest   "/bin/bash"         2 hours ago         Exited (127) About an hour ago                       thirsty_wright      
root@basickarl:~# docker attach --sig-proxy=false e4
FATA[0000] You cannot attach to a stopped container, start it first 
root@basickarl:~# docker start e4
e4
root@basickarl:~# docker attach --sig-proxy=false e4
FATA[0000] You cannot attach to a stopped container, start it first 
root@basickarl:~# 

没有多少说真的,我期待容器启动并保持upp。这里是日志:

Not much to say really, I'm expecting the container to start and stay upp. Here are logs:

root@basickarl:~# docker logs e4
root@basickarl:~# 


推荐答案

您正在尝试运行 bash ,一个需要tty才能操作的交互式shell。使用 -d 在分离模式下运行此功能并不真实,但可以通过添加 -it 到命令行,这确保容器具有与之相关联的有效tty,并且 stdin 保持连接:

You are trying to run bash, an interactive shell that requires a tty in order to operate. It doesn't really make sense to run this in "detached" mode with -d, but you can do this by adding -it to the command line, which ensures that the container has a valid tty associated with it and that stdin remains connected:

docker run -it -d -p 52022:22 basickarl/docker-git-test

您通常会运行某种长期的非交互式过程(如 sshd 或Web服务器,或数据库服务器或流程管理器,如 systemd supervisor )。

You would more commonly run some sort of long-lived non-interactive process (like sshd, or a web server, or a database server, or a process manager like systemd or supervisor) when starting detached containers.

如果您尝试运行像 sshd 这样的服务,则不能简单地运行 service ssh start 。这将取决于您在容器内运行的分发 - 执行以下两项操作之一:

If you are trying to run a service like sshd, you cannot simply run service ssh start. This will -- depending on the distribution you're running inside your container -- do one of two things:


  • 尝试联系流程管理器,如 systemd upstart 启动该服务。因为没有服务管理器运行,这将失败。

  • It will try to contact a process manager like systemd or upstart to start the service. Because there is no service manager running, this will fail.

它实际上将开始 sshd ,但它将在后台启动。这意味着(a)服务sshd开始命令退出,这意味着(b)Docker认为你的容器失败,所以它清理所有的东西。

It will actually start sshd, but it will be started in the background. This means that (a) the service sshd start command exits, which means that (b) Docker considers your container to have failed, so it cleans everything up.

如果要在容器中运行只是 ssh,请考虑一个例子,如这个

If you want to run just ssh in a container, consider an example like this.

如果要运行 sshd 和其他流程在容器内,您将需要调查某种流程主管。

If you want to run sshd and other processes inside the container, you will need to investigate some sort of process supervisor.

这篇关于Docker容器不启动(码头启动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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