foreword
I want to learn about Docker systematically, so I will publish a series of blogs to record my learning process.
describe
I want to make an image with a Java runtime environment based on the Centos7 version, so it can be seen that this image is divided into two layers, one is Centos7, and the other is JDK
step
Step 1. Centos image
Here you can find an existing Centos7 image, which I found from NetEase Cloud.
address
https://c.163yun.com/hub#/m/repository/?repoId=1055There
are many versions here, choose what you need, I chose 7.0
download
docker pull hub.c.163.com/public/centos:7.0
In this way, the ready-made centos image is downloaded to the local, which can be viewed in the command line mode by the following command:
docker images
Step 2. JDK
At this point, a JDK package needs to be prepared, which I found from the oracle official website.
address
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Remember: Choose the appropriate JDK package according to the system version of centos, for example, if you have a 64 operating system, choose x64.
Step 3. Make a mirror
Dockerfile
Here the image is based on Dockerfile, so you need to prepare a Dockerfile first.
FROM hub.c.163.com/public/centos:7.0
MAINTAINER Silence <chenmohaha_2000@163.com>
ENV TZ "Asia/Shanghai"
ADD jdk-8u161-linux-x64.tar.gz /usr/local
ENV JAVA_HOME /usr/local/jdk1.8.0_161
The syntax is not difficult, from top to bottom are:
Basic image, that is, based on which image to make a JDK image, here is centos7.0; the
author, write your own;
set the time zone variable;
add the locally downloaded JDK to the specific directory of the centos image, which will be automatically decompressed here;
set Java environment variables;
make
docker build -t centos7_jdk8 .
Use the docker build -t command to create the image, followed by the name of the image.
run
docker run -d -it e20f7c53086a /bin/bash
Use docker run -d -it to start a container in interactive mode and execute the /bin/bash command inside the container.
into the mirror
docker exec -it 47473dc08dfa /bin/bash
If you want to confirm whether the JDK has been put into the container you started, you need to enter the container first.
mirror label
docker tag e20f7c53086a hub.c.163.com/keysilence/store/docker/centos7_jdk8:1.0
Tag your own images.
upload image
docker push hub.c.163.com/keysilence/store/docker/centos7_jdk8:1.0
Here is to upload the image to the mirror warehouse of 163 Cloud, of course, you need to log in to the mirror warehouse of the cloud first:
docker login hub.c.163.com
Just enter your username and password, and then you can see the image you made in the cloud.