Continuation-docker: Advantages and installation methods and basic command integration

Table of contents

1. Introduction: 

1.1 Advantages of docker: 

1.2 Simple understanding of docker 

2. Command installation 

2.1 Install yum plugins

ps: Prompt that there is no permission and add sudo, the root user does not need

 2.2 Set the yum warehouse address

ps: Set up multiple mirror repositories, if not set, the download may slow down

ps: as shown in the picture

 2.3 Update cache

 2.4 install docker

2.5 View docker version

3. Start docker-------------

3.1 Start the docker service

3.2 Set the boot to start automatically

3.3 stop docker service

 3.4 Mirror Acceleration

 3.5 output daemon.json

3.6 Reload docker configuration

3.7 restart docker

3.8 View mirror configuration

3.9 Run the helloworld container, it will not be downloaded automatically

4. Basic instructions used by docker 

4.1 Check the docker image

 4.2 View docker container

4.3 docker delete container

---> If there is a container still occupying this image, deleting it will report an error

---> You need to delete the container to which this image is applied first and then delete 

 ---> Special Note: If the image container is deleted directly, it will not be deleted 

 4.4 docker pull pull

 4.5 Run the image

5. Make a mirror image

5.1 Download centos image

 -> Official website effect (as shown in the picture)

-> Download operation (as shown in the picture)

5.2 Download the centos7 image locally

5.3 Then pull this compressed package into the Windows system

--> How to use (as shown in the figure): 

5.4 Enter the container (host machine enters) and exit

-> As shown 

​edit

5.5 The standard operations of docker running in the background include:

5.6 Delete container: 

5.7 Delete mirror

6. Maintenance after container creation

6.1 View container information

6.2 View container log information

7. Create a container mount (data volume)

7.1 Create a data volume

7.2 View data volume

 7.3 Check the specified data volume information

7.4 configure jdk

   --> Create a file Dockerfile and add configuration

7.5 Build an image using Dockerfile

---> Command: docker build -t jdk:8 .   

 7.6 View environment variables

8. Summary and follow-up portal


1. Introduction: 

1.1 Advantages of docker: 

  1. Isolation: Docker uses containers to isolate different applications and environments, which prevents applications from interfering with each other and allows for better resource management.

  2. Portability: Docker containers can easily run in different environments to achieve true portability without worrying about application problems due to different operating environments.

  3. Scalability: With Docker it is easy to scale the application, increasing or decreasing the number of containers as needed.

  4. Faster Deployment: Due to the lightweight nature of Docker containers, deploying applications becomes very fast and easy.

  5. Better resource utilization: Docker can make full use of system resources and run multiple applications simultaneously in different containers to achieve better resource utilization.

  6. Better management and maintenance: The management and maintenance of Docker is very simple, you can easily update and upgrade the applications in the container, and you can use some tools of Docker to monitor and manage the running status of the container.

1.2 Simple understanding of docker 

It is divided into containers and hosts, that is, the ports of containers can be mapped with the same ports of different hosts

Just like a virtual machine, each container is independent of each other and does not affect each other. Then these containers are placed in different grids in a big house. Take redis as an example. There can be multiple containers with port 6379, but only one host port can be mapped to 6380, etc.

2. Command installation 

2.1 Install yum plugins

ps: Prompt that there is no permission and add sudo, the root user does not need

yum install -y yum-utils

 2.2 Set the yum warehouse address

ps: Set up multiple mirror repositories, if not set, the download may slow down

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
sudo yum-config-manager \
     --add-repo \
     http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

ps: as shown in the picture

 2.3 Update cache

sudo yum makecache fast

 2.4 install docker

Repeated downloads due to poor network environment

sudo yum install -y docker-ce docker-ce-cli containerd.io

2.5 View docker version

docker -v

3. Start docker-------------

3.1 Start the docker service

systemctl start docker

3.2 Set the boot to start automatically

systemctl enable docker

3.3 stop docker service

systemctl stop docker

 3.4 Mirror Acceleration

Configure the accelerator to speed up. Modify the configuration file /etc/docker/daemon.json

cat <<EOF > /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"
  ],
  "max-concurrent-downloads": 10,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
    },
  "data-root": "/var/lib/docker"
}
EOF

 3.5 output daemon.json

3.6 Reload docker configuration

systemctl daemon-reload 

3.7 restart docker

systemctl restart docker

3.8 View mirror configuration

 docker info

3.9 Run the helloworld container, it will not be downloaded automatically

Official website: https://hub.docker.com/

docker run hello-world

4. Basic instructions used by docker 

4.1 Check the docker image

docker  images 

 4.2 View docker container

docker ps -a  # (简写) a==all

 

4.3 docker delete container

docker image rm redis

---> If there is a container still occupying this image, deleting it will report an error

---> You need to delete the container to which this image is applied first and then delete 

 

 ---> Special Note: If the image container is deleted directly, it will not be deleted 

 4.4 docker pull pull

 

 4.5 Run the image

docker run hello-world

5. Make a mirror image

To make a mirror, an empty centos mirror (empty system mirror file system) will be downloaded first.

The official mirror warehouse address is https://hub.docker.com

5.1 Download centos image

docker pull centos:7

 -> Official website effect (as shown in the picture)

-> Download operation (as shown in the picture)

5.2 Download the centos7 image locally

5.3 Then pull this compressed package into the Windows system

--> How to use (as shown in the figure): 

5.4 Enter the container (host machine enters) and exit

docker run -it centos:7 bash
docker exec -it centos:7 bash

Note: (Commands can be used in combination) Example: -i -t -dit -d is to run in the background, it means interactive dit has no meaning 

-> As shown 

5.5 The standard operations of docker running in the background include:

1. Check whether the specified image exists locally, and download it from the public warehouse if it does not exist.
2. Create and start a container using the image.
3. Allocate a file system (simplified linux system) and mount a file system outside the read-only image layer. Layer readable and writable layer
4. Bridge a virtual interface from the dual bridge interface configured by the host host to the container
5. Configure an ip address from the address pool to the container
6. Execute the application specified by the user

5.6 Delete container: 

docker stop redis
docker container rm -f redis

#不用停容器 直接删(container可以不写)
docker rm -rf redis

5.7 Delete mirror

docker rmi 镜像id(三到四位就行)

6. Maintenance after container creation

6.1 View container information

docker inspect redis 

6.2 View container log information

docker container logs redis 
docker container logs -f redis

7. Create a container mount (data volume)

7.1 Create a data volume

7.2 View data volume

 7.3 Check the specified data volume information

7.4 configure jdk

   --> Create a file Dockerfile and add configuration

FROM centos:7
ADD jdk-8u51-linux-x64.tar.gz /usr/local/docker
ENV JAVA_HOME=/usr/local/docker/jdk1.8.0_51 \
    PATH=/usr/local/docker/jdk1.8.0_51/bin:$PATH
CMD [‘bash’]

7.5 Build an image using Dockerfile

(Execute the docker command in the directory where the Dockerfile is located)

---> Command: docker build -t jdk:8 .   

Note that there is a point

 

 

 7.6 View environment variables


8. Summary and follow-up portal

Docker installation, deployment and other operations (column)

Guess you like

Origin blog.csdn.net/pingzhuyan/article/details/119376651