为什么Docker容器总是重启?

时间:2018-10-03 14:32:57

标签: docker docker-container

我使用以下命令在后台运行容器:

s = s.Remove(s.LastIndexOf(" "), 1);

dockerfile:

docker run --restart always --name lnmp -v /Users/gedongdong/web:/var/www/ -itd lnmp

start.sh:

FROM alpine:edge
LABEL author=gedongdong2010@163.com

RUN mkdir -p /run/nginx && mkdir -p /shell

RUN echo http://mirrors.aliyun.com/alpine/edge/main > /etc/apk/repositories && \
echo http://mirrors.aliyun.com/alpine/edge/community >> /etc/apk/repositories && \
apk update && apk add --no-cache nginx

COPY vhosts.conf /etc/nginx/conf.d/
COPY start.sh /shell
RUN chmod -R 777 /shell


EXPOSE 80 443 6379

CMD ["/shell/start.sh"]

vhosts.conf:

nginx -c /etc/nginx/nginx.conf
tail -f /dev/null

当我使用 server { listen 80; server_name docker.test; root /var/www; index index.html; } 时:

docker ps -a

docker ps -a 为什么我的容器总是重新启动?

2 个答案:

答案 0 :(得分:1)

#!/bin/sh添加到您的start.sh文件中

#!/bin/sh
nginx -c /etc/nginx/nginx.conf
tail -f /dev/null

为什么容器总是重新启动:

正如Henry在他的评论中指出的,您的设置--restart always就是这样。通常,请记住,当容器的PID 1停止/崩溃时,容器将退出。例如,您的容器显示如下内容:

(请注意问题所在的PID 1行)

docker container exec -it lnmp top -n 1 -b
Mem: 2846060K used, 3256768K free, 62108K shrd, 83452K buff, 1102096K cached
CPU:   2% usr   2% sys   0% nic  95% idle   0% io   0% irq   0% sirq
Load average: 0.09 0.24 0.27 1/892 41
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
   10     9 nginx    S    15372   0%   0   0% nginx: worker process
   12     9 nginx    S    15372   0%   5   0% nginx: worker process
   17     9 nginx    S    15372   0%   1   0% nginx: worker process
   11     9 nginx    S    15372   0%   7   0% nginx: worker process
   18     9 nginx    S    15372   0%   5   0% nginx: worker process
   15     9 nginx    S    15372   0%   4   0% nginx: worker process
   14     9 nginx    S    15372   0%   1   0% nginx: worker process
   16     9 nginx    S    15372   0%   4   0% nginx: worker process
    9     1 root     S    14924   0%   6   0% nginx: master process nginx -c /etc/nginx/nginx.conf
    1     0 root     S     1592   0%   1   0% {start.sh} /bin/sh /shell/start.sh
   34     0 root     R     1532   0%   4   0% top -n 1 -b
   13     1 root     S     1524   0%   2   0% tail -f /dev/null

答案 1 :(得分:0)

对我来说,它是由于权限问题而发生的。我的机器的密码已更改,在Docker机器中未更新。

要在终端中对其进行调试,请编写以下代码 日志