Docker container -- create a custom jdk1 8 mirroring
background
During our daily development, we will encounter all kinds of strange problems (stepping on the pit o(╯□ ╯ system) o). This common problem series is the record article series of some problems I encounter every day. Here, we will sort it out and share it with you, so that their little friends who are still in the pit can climb out with ropes. At the same time, you are also welcome to leave messages or private letters to me about your problems. I'll see if they can be solved for you.
development environment
- System: Ubuntu
- Tool: docker
content
Without much nonsense, go straight to the topic:
1. Create the directory we use this time in the host and enter it
mkdir dockerfile_create && cd dockerfile_create/ mkdir docker_jdk && cd docker_jdk/
2. Download jdk1 8. Store it in the docker we just created_ JDK directory, and start the third step under this path.
visit https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html To download, you need to have an oracle account. You can register one directly or download it at the following address Link: https://pan.baidu.com/s/1n9ulyRlxVsVs4aOxoCIe-w Extraction code: nsjw
3. Write Dockerfile
vim Dockerfile
The contents of the document are as follows
# Basic image file FROM centos:latest # Creator of this image MAINTAINER cnhuashao # Enter working directory WORKDIR /opt # Create a directory we need RUN mkdir /opt/java # Put the software package we prepared into the folder we just created ADD jdk-8u202-linux-x64.tar.gz /opt/java/ # Setting environment variables ENV JAVA_HOME /opt/java/jdk1.8.0_202 ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH $JAVA_HOME/bin/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ENV PATH $JAVA_HOME/bin:$PATH
Note that the Dockerfile above is a fixed name and cannot be modified at will. Otherwise, this error will be reported
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/cnhuashao/dockerfile_create/docker_jdk/Dockerfile: no such file or directory
4. Start Compiling Based on the above file
docker build -t='centos_jdk' .
Note [.] after the command, Indicates to search in the current directory, - t is to specify an image name, which can be omitted
cnhuashao@cnhuashao:~/dockerfile_create/docker_jdk$ docker build -t='centos_jdk' . Sending build context to Docker daemon 194MB Step 1/9 : FROM centos:latest ---> 5d0da3dc9764 Step 2/9 : MAINTAINER cnhuashao ---> Running in 598c894822dd Removing intermediate container 598c894822dd ---> 24bd4c5e0cb9 Step 3/9 : WORKDIR /opt ---> Running in 8ba6c094071a Removing intermediate container 8ba6c094071a ---> 0627b2aa523e Step 4/9 : RUN mkdir /opt/java ---> Running in e26cd5ab1936 Removing intermediate container e26cd5ab1936 ---> 55f75b7c63c8 Step 5/9 : ADD jdk-8u202-linux-x64.tar.gz /opt/java/ ---> f4de75816469 Step 6/9 : ENV JAVA_HOME /opt/java/jdk1.8.0_202 ---> Running in bfe5b73e056f Removing intermediate container bfe5b73e056f ---> ef7bc968af7d Step 7/9 : ENV JRE_HOME $JAVA_HOME/jre ---> Running in 289ec0ed9b4c Removing intermediate container 289ec0ed9b4c ---> e338d2e42572 Step 8/9 : ENV CLASSPATH $JAVA_HOME/bin/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ---> Running in c31b1a27d5c9 Removing intermediate container c31b1a27d5c9 ---> a38976712316 Step 9/9 : ENV PATH $JAVA_HOME/bin:$PATH ---> Running in fd49d2cb3ae3 Removing intermediate container fd49d2cb3ae3 ---> c62ad4394489 Successfully built c62ad4394489 Successfully tagged centos_jdk:latest
centos is used in our image. When there is no local, it will be automatically pulled according to the preconfigured (default) remote warehouse. The jdk package we use in Dockerfile will be automatically decompressed to the specified directory during compilation.
5. Create a container and enter the test
cnhuashao@cnhuashao:~/dockerfile_create/docker_jdk$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos_jdk latest c62ad4394489 2 minutes ago 634MB cnhuashao@cnhuashao:~/dockerfile_create/docker_jdk$ docker run -it centos_jdk /bin/bash [root@f7565c0dcf12 opt]# java -version java version "1.8.0_202" Java(TM) SE Runtime Environment (build 1.8.0_202-b08) Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
OK, so far our local image has been created. In the next article, we will talk about how to put it under our own docker hub account. Welcome continuous attention
This document declares that:
Works by cn Huashao use Creative Commons Attribution - non commercial use 4.0 international license agreement License.