forked from docs/doc-exports
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com> Co-authored-by: Dong, Qiu Jian <qiujiandong1@huawei.com> Co-committed-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
49 lines
4.6 KiB
HTML
49 lines
4.6 KiB
HTML
<a name="cce_bestpractice_0008"></a><a name="cce_bestpractice_0008"></a>
|
|
|
|
<h1 class="topictitle1">Compiling the Dockerfile</h1>
|
|
<div id="body1513917418808"><p id="cce_bestpractice_0008__p1898619481286">An image is the basis of a container. A container runs based on the content defined in the image. An image has multiple layers. Each layer includes the modifications made based on the previous layer.</p>
|
|
<p id="cce_bestpractice_0008__p8713444275">Generally, Dockerfiles are used to customize images. Dockerfile is a text file and contains various instructions. Each instruction is used to build an image layer. That is, each instruction describes how to build an image layer.</p>
|
|
<p id="cce_bestpractice_0008__p8060118">This section describes how to compile a Dockerfile file.</p>
|
|
<div class="note" id="cce_bestpractice_0008__note5662131212173"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_bestpractice_0008__p14662151213179">Dockerfiles vary according to applications. Dockerfiles need to be compiled based on actual service requirements.</p>
|
|
</div></div>
|
|
<div class="section" id="cce_bestpractice_0008__section0594336273"><h4 class="sectiontitle">Procedure</h4><ol id="cce_bestpractice_0008__ol76434436274"><li id="cce_bestpractice_0008__li864354352711"><span>Log in as the <strong id="cce_bestpractice_0008__b118354532651856">root</strong> user to the device running Docker.</span></li><li id="cce_bestpractice_0008__li1072615513149"><span>Compile a Dockerfile.</span><p><p class="litext" id="cce_bestpractice_0008__p57888614204620"><strong id="cce_bestpractice_0008__b35812198204933">vi Dockerfile</strong></p>
|
|
<p id="cce_bestpractice_0008__p6888865204937">The content is as follows:</p>
|
|
<pre class="screen" id="cce_bestpractice_0008__screen20151151891616"># Centos:7.1.1503 is used as the base image.
|
|
FROM centos:7.1.1503 <strong id="cce_bestpractice_0008__b11393124325319"> </strong>
|
|
# Create a folder to store data and dependency files. You are advised to write multiple commands into one line to reduce the image size.
|
|
RUN mkdir -p /usr/local/mongodb/data \
|
|
&& mkdir -p /usr/local/mongodb/bin \
|
|
&& mkdir -p /root/apache-tomcat-7.0.82 \
|
|
&& mkdir -p /root/jdk1.8.0_151
|
|
|
|
# Copy the files in the apache-tomcat-7.0.82 directory to the container path.
|
|
COPY ./apache-tomcat-7.0.82 /root/apache-tomcat-7.0.82
|
|
# Copy the files in the jdk1.8.0_151 directory to the container path.
|
|
COPY ./jdk1.8.0_151 /root/jdk1.8.0_151
|
|
# Copy the files in the mongodb-linux-x86_64-rhel70-3.2.9 directory to the container path.
|
|
COPY ./mongodb-linux-x86_64-rhel70-3.2.9/bin /usr/local/mongodb/bin
|
|
# Copy start_tomcat_and_mongo.sh to the /root directory of the container.
|
|
COPY ./start_tomcat_and_mongo.sh /root/
|
|
|
|
# Enter Java environment variables.
|
|
RUN chown root:root -R /root \ <strong id="cce_bestpractice_0008__b1311123194419"> </strong>
|
|
&& echo "JAVA_HOME=/root/jdk1.8.0_151 " >> /etc/profile \
|
|
&& echo "PATH=\$JAVA_HOME/bin:$PATH " >> /etc/profile \
|
|
&& echo "CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> /etc/profile \
|
|
&& chmod +x /root \
|
|
&& chmod +x /root/start_tomcat_and_mongo.sh
|
|
|
|
# When the container is started, commands in <strong id="cce_bestpractice_0008__b0682115672818">start_tomcat_and_mongo.sh</strong> are automatically run. The file can be one or more commands, or a script.
|
|
ENTRYPOINT ["/root/start_tomcat_and_mongo.sh"] </pre>
|
|
<p id="cce_bestpractice_0008__p18409771">In the preceding information:</p>
|
|
<ul id="cce_bestpractice_0008__ul31470215"><li id="cce_bestpractice_0008__li14796483"><strong id="cce_bestpractice_0008__b147941807851856">FROM</strong> statement: indicates that <strong id="cce_bestpractice_0008__b52706637151856">centos:7.1.1503</strong> is used as the base image.</li><li id="cce_bestpractice_0008__li66059488"><strong id="cce_bestpractice_0008__b842352706195452">Run</strong> statement: indicates that a shell command is executed in the container.</li><li id="cce_bestpractice_0008__li57664488"><strong id="cce_bestpractice_0008__b67611998384">COPY</strong> statement: indicates that files in the local computer are copied to the container.</li><li id="cce_bestpractice_0008__li11833133083019"><strong id="cce_bestpractice_0008__b842352706195635">ENTRYPOINT</strong> statement: indicates the commands that are run after the container is started.</li></ul>
|
|
</p></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="cce_bestpractice_0340.html">Procedure</a></div>
|
|
</div>
|
|
</div>
|
|
|