Table of contents
1.3 Create a mirror image using a script
2.1 Introduction to private warehouse:
2.2 Private warehouse construction and configuration
2.3 Upload the image to the private warehouse:
1、Dockerfile
1.1 What is a Dockerfile
A Dockerfile is a script consisting of a series of commands and parameters that are applied to a base image and ultimately create a new image.
- Dockerfile is a text file used to define the process of building a Docker image. It contains a series of instructions and configurations to instruct the Docker engine to build a new image based on the base image.
- By writing a Dockerfile, an automated and repeatable build process can be achieved, improving the reliability and maintainability of container images.
- Dockerfile writing specifications and best practices can help optimize the image building process, reduce image size, and improve build speed
For developers: it can provide a completely consistent development environment for the development team;
For testers: You can directly take the image built during development or build a new image through the Dockerfile file to start working;
For operation and maintenance personnel: during deployment, seamless migration of applications can be achieved
1.2 Common commands
Order | effect |
---|---|
FROM image_name:tag | Defines which base image to use to start the build process |
MAINTAINER user_name | Declare the creator of the image |
ENV key value | Set environment variables (multiple entries can be written) |
RUN command | It is the core part of Dockerfifile (multiple entries can be written) |
ADD source_dir/fifile dest_dir/fifile | Copy the host's file to the container, if it is a compressed file, it will be automatically decompressed after copying |
COPY source_dir/fifile dest_dir/fifile | Similar to ADD, but cannot decompress if there is a compressed file |
WORKDIR path_dir | set working directory |
1.3 Create a mirror image using a script
Create a directory (store tar package, dockerfile location):
mkdir -p /usr/local/dockerjdk8
Download the tar package of jdk here and move the tar package to the dockerjdk8 directory
Edit the Dockerfile:
vim Dockerfile
Edit content:
FROM centos:7 MAINTAINER xxx WORKDIR /usr RUN mkdir /usr/local/java ADD jdk-8u60-linux-x64.tar.gz /usr/local/java ENV JAVA_HOME /usr/local/java/jdk1.8.0_60 ENV PATH $JAVA_HOME/bin:$PATH
Unzip the tar package:
docker build -t='jdk1.8' .
2. Docker private warehouse
2.1 Introduction to private warehouse:
- Docker private warehouse is a centralized platform for storing and managing custom container images, which can build, store and share images in the internal network.
- Building a Docker private warehouse can provide faster image download speed, better security and better team collaboration experience.
- The management of Docker's private warehouse includes access control, backup and recovery, high availability and load balancing, etc., which can be configured and optimized according to actual needs.
2.2 Private warehouse construction and configuration
Pull the private warehouse image:
docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete
0d96da54f60b: Pull complete
5b27040df4a2: Pull complete
e2ead8259a04: Pull complete
3790aef225b9: Pull complete
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
Start the private repository container:
docker run -di --name=registry -p 5000:5000 registry
541b70741fa03693e6d3acdc7da977a2b123fdc66f6123aeb1fd37f24b130c7a
Open the browser and enter the address http://192.168.159.161:5000/v2/_catalog to access:
The display here indicates that the private warehouse is built successfully, but the content is still empty and needs to be added:
Fix the daemon.json
{
"registry-mirrors": ["https://registry.dockercn.com","https://mj9kvemk.mirror.aliyuncs.com"],
"insecure-registries":["192.168.159.161:5000"]
}
Restart docker:
systemctl restart docker
Start the registry container:
docker start registr
2.3 Upload the image to the private warehouse:
Tag:
docker tag jdk1.8 192.168.159.161:5000/jdk1.8
Check:
Upload the image to a private repository:
push 192.168.159.161:5000/jdk1.8
Browser view (here the upload is successful):