I run a container in the background using
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
#!/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
You're running a shell in a container, but you haven't assigned a terminal: If you're running a container with a shell (like bash ) as the default command, then the container will exit immediately if you haven't attached an interactive terminal.
In order to prevent the docker container from exiting immediately after creation, tty should be set to true in the docker-compose. yml file. tty: true in docker-compose corresponds to the docker run -it . With tty: true for the service, the created by docker-compose up -d container status is Up .
Dockerfile Command to Keep the Container Running Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.
By default, what happens to a Docker Container when the process it is running exits? The Container reboots and restarts the process.
This did the trick for me:
docker run -dit ubuntu
After it, I checked for the processes running using:
docker ps -a
For attaching again the container
docker attach CONTAINER_NAME
TIP: For exiting without stopping the container type: ^P^Q
A docker container exits when its main process finishes.
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.
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:
while true; do sleep 1000; done
to the end of the script. I don't like this however, as the script should really be monitoring the processes it kicked off.
(I should say I stole that code from https://github.com/sequenceiq/hadoop-docker/blob/master/bootstrap.sh)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With