简体   繁体   English

Ubuntu码头工人运行码头

[英]Ubuntu docker running docker

I have the following docker-compose file: 我有以下docker-compose文件:

version: '2'
services:
  ubuntu:
    image: 'ubuntu:16.04'
    ports:
      - '22:22'

When start this, the container seems to crash, the following are the logs that I see: 启动时,容器似乎崩溃,以下是我看到的日志:

Attaching to playground_ubuntu_1
ubuntu_1  | Error grabbing logs: EOF

playground_ubuntu_1 exited with code 0

My host OS is Ubuntu 16.04 with Docker version 17.12.0-ce, build c97c6d6 . 我的主机操作系统是Ubuntu 16.04, Docker version 17.12.0-ce, build c97c6d6

All of my other containers seem to start normally, but this one just flat out fails on boot. 我的所有其他容器似乎都正常启动,但是这个容器在启动时无法启动。

Exit status in log playground_ubuntu_1 exited with code 0 shows that its expected. 日志playground_ubuntu_1 exited with code 0状态playground_ubuntu_1 exited with code 0表示其预期。 In order to make a container up & running for long, you need to give/define a foreground process for your container. 为了使容器长时间运行并运行,您需要为容器提供/定义前台进程。 I have momentarily edited your compose file - 我暂时编辑了你的撰写文件 -

version: '2'
services:
  ubuntu:
    image: 'ubuntu:16.04'
    ports:
      - '22:22'
    command: "tail -f /dev/null"

Now you run it - 现在你运行它 -

$ docker-compose up -d && docker ps

Your container is up & running now. 您的容器现在正在运行。

This is normal. 这个是正常的。 When you start a container it will run as long as the main process started inside the container is still running. 当您启动容器时,只要容器内的主进程仍在运行,它就会运行。

This process is specified using the CMD command inside a Dockerfile. 使用Dockerfile中的CMD命令指定此过程。 The ubuntu image does not have a CMD as it is intended to be used as a building block for other docker images. ubuntu映像没有CMD因为它旨在用作其他docker映像的构建块。 Thus when you run this image without specifying a command, it exits successful as can be seen from the 0 exit code. 因此,当您在未指定命令的情况下运行此图像时,它会从0退出代码中看出,它会退出成功。

If you want this image to stay alive just for testing, you can specify a command that will keep it living. 如果您希望此图像仅用于测试,则可以指定一个可以使其保持活动的命令。

version: '2'
services:
  ubuntu:
    image: 'ubuntu:16.04'
    ports:
      - '22:22'
    command: "tail -f /dev/null"

Most likely you already use port 22 on your host. 您很可能已在主机上使用端口22 Try to bind container 22 port to another port on your host, for example 2222 尝试将容器22端口绑定到主机上的另一个端口,例如2222

version: '2'
services:
  ubuntu:
    image: 'ubuntu:16.04'
    ports:
      - '2222:22'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM