Is it possible to execute CMD at the middle of docker file?
Now, i want to to write third dockerfile which executes an example Map-Reduce job. But the problem is
Third docker file depends on second hadoop-docker file. fo eg:
FROM sec_doc_file RUN /bin/hadoop fs -mkdir input
It requires hadoop services. But hadoop services ll be started only after running second docker file. But i want to run it as part of third docker file before starting MR job? Is it possible? If so, please provide an example. If not, what could be the other possibilities?
#something like From sec_doc_file #Start_Service RUN /bin/hadoop fs -mkdir input #continue_map_reduce_job
One Solution collect form web for “Is it possible to execute CMD at the middle of docker file?”
The docker image you use as base for the new container is a base for files, not for processes supposed to be running. To do what you want you would need to start the process(es) you need during dockerbuild and run the commands to set up properly. Each
RUN creates a new AUFS layer, but does not keep the possible previous running services. So, if you need a service to be up to perform some setup during
docker build you would need to run it in one line (concatenating commands or with a custom script). Example:
FROM Gops/sec_doc_file RUN path/to/start-all.sh && /bin/hadoop fs -mkdir input
So for setting up HDFS folders and files during docker build you’d need to run the hdfs daemons and perform the action you wish in the same
RUN /etc/hadoop/hadoop-env.sh &&\ /opt/hadoop/sbin/start-dfs.sh &&\ /opt/hadoop/bin/hdfs dfs -mkdir input