我在后台运行一个容器:
docker run --restart always --name lnmp -v /Users/gedongdong/web:/var/www/ -itd lnmp
dockerfile:
FROM alpine:edge
LABEL [email protected]
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"]
start.是:
nginx -c /etc/nginx/nginx.conf
tail -f /dev/null
vhosts.conf:
server {
listen 80;
server_name docker.test;
root /var/www;
index index.html;
}
当我使用docker ps -a
时:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a3910c0dc29 lnmp "/shell/start.sh" 16 minutes ago Restarting (1) 50 seconds ago lnmp
docker ps -a为什么我的容器总是重新启动?
将#!/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
对我来说,这是因为许可问题。我的机器密码已更改,Docker机器中的密码未更新。
要在终端中调试它,请在日志下面编写代码