本文介绍了不能启动“docker start”的简单docker容器命令从创建的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的命令来制作和启动container(create.sh):

  docker build -t foo。 

docker rm bar
docker create --name = bar foo&&& \
docker start bar&& \
docker exec bar sh / bin / echo测试!

Dockerfile:

 code>#/ bin / bash 
FROM centos:7
运行yum update -y

但无法启动:

  $ bash create.sh 
将构建上下文发送到Docker守护进程4.608 kB
步骤1:FROM centos:7
---> 980e0e4c79ec
步骤2:运行yum update -y
--->使用缓存
---> 80b94205920c
成功构建80b94205920c
bar
a1db507225ca7479bdcc3bb3d4e3a863398bf4bf0e9365f507978b11d99df19
bar
守护进程错误响应:容器栏未运行

容器已创建但尚未启动。

解决方案

指定了shell作为 CMD 在启动容器时运行:

  CMD [/ bin / bash] 

Docker容器在进程完成后退出,所以什么发生的是当您开始您的容器,它运行 bash 然后结束,因为没有更多的输入到shell。



使用您的Docker镜像,这样可以预期 - echo 命令在Dockerfile中乘坐 bash 命令:

 >码头运行温度回波'测试'
测试

如果要保持容器运行在后台,那么你需要在容器内的进程继续运行。您可以在创建容器时指定一个命令:

 > docker create temp sleep infinity 
a34a4528b3cfbb7a36fb429d32510c5576831adeb899c07e4596a6b9731c945b
>码头启动a34
a34
> docker exec a34 echo'Test'
测试


I have simple commands for making and starting container (create.sh):

docker build -t foo .

docker rm bar
docker create --name=bar foo && \
docker start bar && \
docker exec bar sh /bin/echo Test!!!

Dockerfile:

#/bin/bash
FROM centos:7
RUN yum update -y

But it cannot be started:

$ bash create.sh
Sending build context to Docker daemon 4.608 kB
Step 1 : FROM centos:7
 ---> 980e0e4c79ec
Step 2 : RUN yum update -y
 ---> Using cache
 ---> 80b94205920c
Successfully built 80b94205920c
bar
a1db507225ca7479bdcc3bb3d4e3a86339827f4bf0e9365f507978b11d99df19
bar
Error response from daemon: Container bar is not running

The container has been created but it hasn't started.

解决方案

The Dockerfile for CentOS specifies the shell as the CMD to run when you start a container:

CMD ["/bin/bash"]

Docker containers exit when the process they started with finishes, so what's happening is when you start your container, it runs bash and then ends, because there's no more input to the shell.

Using your Docker image, this does what you expect - the echo command overrides the bash command in the Dockerfile:

> docker run temp echo 'Test'
Test

If you want to keep a container running in the background, then you need the process inside the container to keep running. You can specify a command when you create the container:

 >docker create temp sleep infinity
a34a4528b3cfbb7a36fb429d32510c5576831adeb899c07e4596a6b9731c945b
> docker start a34
a34
> docker exec a34 echo 'Test'
Test

这篇关于不能启动“docker start”的简单docker容器命令从创建的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:32