SoFunction
Updated on 2025-03-02

An article understands the production, upload, pull and deployment of Docker images

1. Mirror (images)

1. What is mirroring?

(1) According to Baidu Encyclopedia's explanation: Mirroring is a file storage form and a type of redundant. If the data on one disk exists in the same copy on another disk, it is a mirror.

(2) Many files can be made into a mirror file, and they can be placed in a disk with GHOST and other programs, and then opened with GHOST and other software, and then restored to many files. RAID 1 and RAID 10 use mirrors.

(3) Common mirror file formats include ISO, BIN, IMG, TAO, DAO, CIF, and FCD.

Are you even more dizzy after reading it?

In fact, simply put, mirror is an app package, which contains program code, basic systems, dependency libraries, and tools.
To put it simply, it is a bit similar to the APP installation package.

2. The composition and use of mirrors

(1)Dockerfile

: It is the recipe for making mirrored files

Just like a secret recipe passed down from ancestors: Yunnan Baiyao: Linzhi, ginseng, deer antler, Panax notoginseng, etc.

(2)scratch

: It is the most basic docker image, equivalent to a foundation—》Blank image, nothing --》 Starting from scratch

Use other mirrors as basic mirrors: Other mirrors can be expanded as basic – like standing on the shoulders of giants.

But we need to make a mirror with a tall building starting from the ground, step by step 👣

(3) A complete operating system requires:


2. System calls
3. Applications and libraries
wait

bootfs --》What is needed when the container is started

rootfs --》Operation system inside the container

docker save

docker export

principle:

When the container is started, the kernel starts bootfs and then loads the basic image directly, and then loads it layer by layer –》From the bottom up

When accessing files after the container is run, access them from top to bottom, from the writable layer, layer by layer.

3. Why do you need to make your own mirror?

In the past, I downloaded mysql in Linux, and the yum command was needed in the Centos system. After learning the doker technology, what software is needed? You only need to pull it on docker to get it. Docker is like a huge resource library, only things you can't think of, nothing that it doesn't have.

Some students said: It is technology that restricts my imagination of docker and shed tears of regret.

Some students just said that since docker is so convenient and there are so many mirror files on it, why do we still need to make it ourselves? What do you need? Isn't it okay?

However, in companies, you often need to make your own mirror files, because things made by others are often uneasy, or some specific needs cannot be met. Just like when you go to buy Moutai, the merchant says this is Moutai for ten years, so do you believe it? Is this the ten-year Maotai? Don't go to the identification? If you are a rich man, just pretend I didn't say it, hahahaha

2. Steps of mirror production (10 steps)

Step 1: Edit Dockerfile

[root@sc-docker-server ~]# mkdir /mydocker/
[root@sc-docker-server ~]# cd /mydocker/
[root@sc-docker-server mydocker]#

[root@sc-docker-server mydocker]# vim Dockerfile
FROM python:2.7-slim
WORKDIR /app
ADD . /app
RUN pip install --trusted-host   -r 
EXPOSE 80
ENV NAME World
ENV AUTHOR cali
CMD ["python",""]

Step 2: Edit the file

[root@sc-docker-server mydocker]# vim 
Flask
Redis

Step 3: Edit the file, our program file

[root@sc-docker-server mydocker]# vim 
from flask import Flask
from redis import Redis, RedisError
import os
import socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)

app = Flask(__name__)

@("/")
def hello():
    try:
        visits = ("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {visits}"
    return (name=("NAME", "world"), hostname=(), visits=visits)

if __name__ == "__main__":
    (host='0.0.0.0', port=80)

Step 4: Generate the mirror file

[root@sc-docker-server mydocker]#docker build -t sc_friendlyhello_1 .
docker build -t sc_friendlyhello_1 .
Sending build context to Docker daemon  4.608kB
Step 1/9 : FROM python:2.7-slim
 ---> eeb27ee6b893
Step 2/9 : WORKDIR /app
 ---> Using cache
 ---> 81aa71984f63
Step 3/9 : ADD . /app
 ---> Using cache
 ---> a5c7c6ed471c
Step 4/9 : VOLUME ["/data_flask"]
 ---> Using cache
 ---> d4db66a741db
Step 5/9 : RUN pip install --trusted-host   -r 
 ---> Using cache
 ---> bcdee009e5f7
Step 6/9 : EXPOSE 80
 ---> Using cache
 ---> 475474ce55ff
Step 7/9 : ENV NAME World
 ---> Using cache
 ---> 0f03ead6c99b
Step 8/9 : ENV AUTHOR cali
 ---> Using cache
 ---> f844eb0f1a78
Step 9/9 : CMD ["python",""]
 ---> Using cache
 ---> ab30484b56b8
Successfully built ab30484b56b8
Successfully tagged sc_friendlyhello_1:latest
[root@sc-docker-server mydocker]#

Step 5: Check if the mirror is successful

[root@sc-docker-server mydocker]# docker images
REPOSITORY                 TAG        IMAGE ID       CREATED          SIZE
sc_friendlyhello_1         latest     ab30484b56b8   32 minutes ago   159MB

Step 6: Use the mirror to start the container

docker run -d -p 5080:80  --name sc-hello-1 sc_friendlyhello_1

Step 7: Access the container's web service

curlorchromeBrowser access
Hostip:5080
Hello World!
Hostname: f4aeb5d5305a
Visits: cannot connect to Redis, counter disabled

Because the redis database container is not started, the flask web service cannot connect to the redis database

Step 8: Start the redis container

docker run -d -p 6379:6379 --name sc-redis-1 redis

Step 9: Start a container that makes your own image again and link to the redis container

docker run -d --name sc-hello-2 -p 5081:80 --link sc-redis-1:redis sc_friendlyhello_1

Step 10: Access the container's web service

curlorchromeBrowser access
Hostip:5081
Hello World!
Hostname: aad7da1892b5
Visits: 15

3. Mirror production homework

Operation

1. Upgrade the basic image in the sc_friendlyhello_1 image to python:3.9
My own image is renamed to sc_friendlyhello_2
2. Start container and redis container, test access **

Job steps:

Install uploaded files

root@sc-docker-server ~]# yum install lrzsz -y Install uploaded softwareLast dimensional data expiration check:0:25:32 forward,Execute on 2021Year08moon18day Wednesday 09hour52point02Second。
Software Package lrzsz-0.12.20-43.el8.x86_64 Installed。
Dependency resolution。
No processing is required。
complete!
[root@sc-docker-server ~]#

Step 1: Download the app source code

/docker/getting-started existwindowsDownload in,Then upload tolinuxinside yum install git -y 

linuxinside: git clone /califeng/

Step 2: Unzip the app source code compression package

[root@sc-docker-server ~]# yum install zip unzip -y

    [root@sc-docker-1 ~]# unzip  

Step 3: Enter the app directory and create a new Dockerfile

    [root@sc-docker-1 getting-started-master]# cd app/
    [root@sc-docker-1 app]# vim Dockerfile
FROM node:12-alpine
WORKDIR /app
COPY  . .
RUN yarn install --production
CMD ["node", "src/"]

Step 4: Make a mirror

[root@sc-docker-1 app]# docker build -t getting-started .
-t getting-started It is the name of the specified image,You can define your own name



[root@sc-docker-1 app]# docker images View the created imageREPOSITORY                TAG         IMAGE ID       CREATED          SIZE
getting-started           latest      5b903e857b8c   25 seconds ago   179MB
redis                     latest      cc69ae189a1a   2 days ago       105MB
nginx                     1.19.7      35c43ace9216   7 days ago       133MB
nginx                     latest      35c43ace9216   7 days ago       133MB
mysql                     5.7.33      5f47254ca581   2 weeks ago      449MB
nginx                     1.19.6      f6d0b4767a6c   6 weeks ago      133MB
node                      12-alpine   0206ff8a5f9e   7 weeks ago      88.9MB
richarvey/nginx-php-fpm   latest      5c3ad1891297   5 months ago     506MB
hello-world               latest      bf756fb1ae65   13 months ago    13.3kB
jcdemo/flaskapp           latest      4f7a2cc79052   2 years ago      88.7MB
[root@sc-docker-1 app]#

Step 5: Start the container of the mirrored image you made

[root@sc-docker-1 app]# docker run -dp 3000:3000 getting-started
8f150a72e7d2d1650685b00a18d237469fa07c8cd56977773dd266b281a3b4ad
[root@sc-docker-1 app]# docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS         PORTS                    NAMES
8f150a72e7d2   getting-started   "…"   5 seconds ago   Up 3 seconds   0.0.0.0:3000->3000/tcp   strange_benz
deabb58e01b0   nginx             "/docker-entrypoint.…"   26 hours ago    Up 2 hours     0.0.0.0:6655->80/tcp     chenpeng
[root@sc-docker-1 app]# 

Step 6: Open the browser to access the website in the container

Website in the container: http://192.168.0.161:3000/

Summarize

1. Mirror production is a necessary skill in docker technology. If you say you know how to docker, others will definitely ask you if mirror production? If you say you do what you do to make that thing, others will smile. When you think in your heart, this person's skills must be very low, and you can't even know this, and you even say you can docker, haha.

2. There are detailed steps for mirror production later. The ten-step mirror production method will teach you how to do it. Take your time and do it step by step.

This is the article about Docker image production, upload, pull and deployment. For more related Docker image production, upload, pull and deployment, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!