1. What is DockerFile
In short, it is to describe how to build a mirror image of a script file, which is described step by step how to build an image file comes;
2, the steps to build the mirror:
(1)书写DockerFile文件
(2)通过docker build生成新镜像
(3)通过docker run命令运行
3, where the construction of our new image need to use our software FileZilla
FileZilla: is a free open source FTP software, is divided into client and server versions, it is a fast and reliable FTP client and server-side open-source program, with a variety of features, direct interface;
FileZilla basic functions: can HTTP upload, download (need server support), custom commands, perform site management, anti-daze function (FTP server and some users will be out of a daze for too long, strung-out on the user have to login again)
4, Docker actual image constructed jdk
1, first, open VMWare virtual machine and log in using the secure CRT Linux server;
2, then, use the command to create a directory in the root directory of the host: mkdir -p /usr/local/mydocker
wherein represents -p create multi-level directory;
3, using the cd cut into the directory: cd /usr/local/mydocker
(The following operations are performed in the directory, using the instruction: pwd
to display the current path is located)
4, then we use a prepared FileZilla software to connect docker host, and the jdk (liunx archive) uploaded to our just created on a good path on the host;
5, after the success we can enter ll uploaded on secureCRT command for viewing;
6, Dockerfile directly create a file in just created usr / local / mydocker folder / vim command and edit: vim Dockerfile
Press i to enter the edit window, and enter the following command:
#首先是一个基础镜像
FROM centos:7
#指定镜像创建者信息
MAINTAINER zjm
#切换工作目录(当我们使用该镜像创建好一个容器后,他会自动进入到该路径下)
WORKDIR /usr/local
#创建一个存放jdk的路径
RUN mkdir /usr/local/java
#将jdk压缩包复制并解压到容器中/usr/local/java
ADD jdk-8u171-linux-x64.tar.gz /usr/local/java
#配置java环境变量(这里路径一定要写对,不然环境变量配置会失败)
ENV JAVA_HOME /usr/local/java/jdk1.8.0_171
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH
CMD ["/bin/bash"]
(Note: We configured java environment variable, pay more behind the jdk1.8.0_171, because after jdk solution linux version of compression there is also a folder called "jdk1.8.0_171", we want to access the contents inside it may therefore add jdk1.8.0_171)
7, Dockerfile After saving the file, use the syntax to build its image building: docker build -t jdk:1.8 .
(Note: jdk arbitrarily named for our image name, tag number is 1.8, but also remember that back plus point (), this point there's still space. )
because we are in command under / usr / local / mydockers carried out, it Dockerfile file is created in this file, if in a different folder, we need to use the [option] -f specify its file path;
8. Finally, we use docker images you can clearly see the image we have just built by dockerFile file;
9, then we use to build a good image to create a container, instructions:
docker run -it --name=myjdk jdk:1.8
After you've created into the container: docker exec -it myjdk /bin/bash
use ls can see the container files in the current directory;