为什么docker容器会立即退出 [英] Why docker container exits immediately
问题描述
我使用
docker run -d --name hadoop h_Service
它很快退出.但是如果我在前台运行,它工作正常.我使用
it exits quickly. But if I run in the foreground, it works fine. I checked logs using
docker logs hadoop
没有错误.有什么想法吗?
there was no error. Any ideas?
DOCKERFILE
FROM java_ubuntu_new
RUN wget http://archive.cloudera.com/cdh4/one-click-install/precise/amd64/cdh4-repository_1.0_all.deb
RUN dpkg -i cdh4-repository_1.0_all.deb
RUN curl -s http://archive.cloudera.com/cdh4/ubuntu/precise/amd64/cdh/archive.key | apt-key add -
RUN apt-get update
RUN apt-get install -y hadoop-0.20-conf-pseudo
RUN dpkg -L hadoop-0.20-conf-pseudo
USER hdfs
RUN hdfs namenode -format
USER root
RUN apt-get install -y sudo
ADD . /usr/local/
RUN chmod 777 /usr/local/start-all.sh
CMD ["/usr/local/start-all.sh"]
start-all.sh
start-all.sh
#!/usr/bin/env bash
/etc/init.d/hadoop-hdfs-namenode start
/etc/init.d/hadoop-hdfs-datanode start
/etc/init.d/hadoop-hdfs-secondarynamenode start
/etc/init.d/hadoop-0.20-mapreduce-tasktracker start
sudo -u hdfs hadoop fs -chmod 777 /
/etc/init.d/hadoop-0.20-mapreduce-jobtracker start
/bin/bash
推荐答案
Docker 容器在其主进程完成时退出.
A docker container exits when its main process finishes.
在这种情况下,它会在您的 start-all.sh
脚本结束时退出.我对 hadoop 了解得不够多,无法告诉您在这种情况下如何执行此操作,但是您需要让某些程序在前台运行,或者使用诸如 runit 或 supervisord 之类的进程管理器来运行这些进程.
In this case it will exit when your start-all.sh
script ends. I don't know enough about hadoop to tell you how to do it in this case, but you need to either leave something running in the foreground or use a process manager such as runit or supervisord to run the processes.
如果你不指定-d
,我认为你一定误会了它的工作原理;它应该具有完全相同的效果.我怀疑你使用稍微不同的命令或使用 -it
启动它,这会改变事情.
I think you must be mistaken about it working if you don't specify -d
; it should have exactly the same effect. I suspect you launched it with a slightly different command or using -it
which will change things.
一个简单的解决方案可能是添加如下内容:
A simple solution may be to add something like:
虽然为真;睡1000;完毕
到脚本的结尾.然而,我不喜欢这样,因为脚本应该真正监控它启动的进程.
to the end of the script. I don't like this however, as the script should really be monitoring the processes it kicked off.
(我应该说我从 https://github.com/sequenceiq/窃取了该代码hadoop-docker/blob/master/bootstrap.sh)
这篇关于为什么docker容器会立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!