Ubuntu容器不断重启 [英] Ubuntu container keep restarting

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

问题描述

我正在使用docker-compose添加一个新的ubuntu容器,但该容器不断重启,我不知道为什么...我可以检查的任何线索吗?

I'm using docker-compose to add a new ubuntu container but the container keeps restarting and I don't know why... any clue of what I can check ?

这是我的docker-compose服务

here my docker-compose service:

  ubuntu:
    image: ubuntu
    container_name: ubuntu
    network_mode: host
    restart: unless-stopped
    volumes:
      - /mnt:/NAS:rw
    environment:
      - TZ="Asia/Shanghai"

这是 docker ps 输出:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                          PORTS                                            NAMES
6c084528838c        ubuntu              "/bin/bash"              6 minutes ago       Restarting (0) 18 seconds ago                                                    ubuntu

我在Ubuntu服务器17.04上使用Docker 17.09,并且正在使用以下别名运行容器:

i'm using Docker 17.09 on Ubuntu server 17.04 and I'm running the container with this alias:

alias dcrun='docker-compose -f /home/docker-compose.yml'

dcrun up -d ubuntu

谢谢

推荐答案

由于您尚未在Docker中定义任何 command: entrypoint:,因此这是非常可预期的撰写.

This is quite expected since you haven't defined any command: or entrypoint: in the docker compose.

Ubuntu图像默认情况下具有 bash 命令作为 CMD ,这实际上不是一个前台过程.参考- https://github.com/dockerfile/ubuntu/blob/master/Dockerfile

Ubuntu image by default has bash command as CMD which isn't really a foreground process. Ref - https://github.com/dockerfile/ubuntu/blob/master/Dockerfile

如果以交互模式(-i)运行它,则您将自动进入 bash -

If you run it in interactive mode(-i), you will dive into bash automatically -

$ docker run -it ubuntu 
root@8d6ac0591d88:/# 

因此,一旦 bash 命令退出您的容器时也会死亡,但是由于您的 restart:除非停止策略,Docker守护进程一直尝试重新启动它.

Hence, once the bash command exits your container also dies but due to your restart: unless-stopped policy, Docker daemon keeps trying to restart it.

如果您希望将容器装满&与compose一起运行,请尝试如下定义前台进程-

If you want your container to be up & running with compose, try defining a foreground process as below -

  ubuntu:
    image: ubuntu
    container_name: ubuntu
    network_mode: host
    restart: unless-stopped
    volumes:
      - /mnt:/NAS:rw
    environment:
      - TZ="Asia/Shanghai"
    command: "tail -f /dev/null"

您的容器不会立即重新启动-

Your container will not restart now -

$ docker ps
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS                      PORTS                     NAMES
cee860adf641        ubuntu                             "tail -f /dev/null"      5 seconds ago       Up 3 seconds                                          ubuntu

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

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