Detailed explanation of Docker usage under CentOS8

Detailed explanation of Docker usage under CentOS8

1. Installation of Docker under CentOS8

curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
yum install -y https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm
yum install -y docker-ce

2. Starting and stopping Docker under CentOS8

Start command systemctl start docker
service docker start

Shutdown command systemctl stop docker
service docker stop

View Docker status docker info

3. Image Accelerator Configuration

1. Visit Alibaba Cloud

https://www.aliyun.com/

2. Configure the mirror acceleration address

Enter the console

insert image description here
insert image description here
insert image description here
insert image description here

View the configured mirror acceleration address

docker info

See the Registry Mirrors: section.

4. Basic Operations of Docker

Basic Operation

Advanced Operations

Use of the orchestration tool docker-compose1

Use of the orchestration tool docker-compose2

5. Other Techniques

1. Kill the docker container

docker kill container ID or name

2. View Docker container logs

docker logs -f -t container_name

3. Check which processes are running in the docker container

docker top container_name

4. Run the docker container without automatically exiting and then entering the container

docker run -d -it 63bd2b510f17 /bin/bash
Or docker run -id d70eaf7277ea # Sometimes it doesn't work docker exec -it 03d80e28c244 /bin/bash

Note that /bin/bash should be placed at the end.

5. View the container configuration information

docker inspect 03d80e28c244

6. Copy files/directories between container and host

docker cp --help

Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
	docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem

Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.

Options:
 -a, --archive Archive mode (copy all uid/gid information)
 -L, --follow-link Always follow symbol link in SRC_PATH

6. One-click packaging of docker images in IDEA

1. Modify Docker service configuration

vim /usr/lib/systemd/system/docker.service

Found the following

insert image description here

Add the following content at the end of the red mark in the above picture

-H unix:///var/run/docker.sock -H 0.0.0.0:2375

# -H unix:///var/run/docker.sock : Start an external host service and use the docker.sock file for management.
# -H 0.0.0.0:2375 : What client IPs are allowed to access the current service, and what is the port number exposed by the current service. 2375 is a custom port.

systemctl daemon-reload
systemctl restart docker

2. Introduce corresponding plug-ins in POM file

<build>
 <plugins>
 <plugin>
 <groupId>com.spotify</groupId>
 <artifactId>docker-maven-plugin</artifactId>
 <version>1.2.2</version>
 <configuration>
 <imageName>projects/eureka:1.0</imageName> <!--Specify the image name warehouse/image name: label-->
 <baseImage>openjdk:latest</baseImage> <!--Specify the base image-->
 <dockerHost>http://192.168.74.131:2375</dockerHost> <!-- Specify the service deployment server warehouse address-->
 <entryPoint>["java","-jar","/${project.build.finalName}.jar"]</entryPoint> <!-- Command executed when the container is started-->
 <exposes>
 <expose>8761</expose><!-- Publish port -->
 </exposes>
 <resources>
 <resource>
 <targetPath>/</targetPath> <!-- Specify the directory path to be copied, here is the current directory-->
 <directory>${project.build.directory}</directory> <!-- Specify the root directory to be copied, here is the target directory -->
 <include>${project.build.finalName}.jar</include> <!-- Specify the file to be copied, here refers to the final generated jar package -->
 </resource>
 </resources>
 </configuration>
 </plugin>
 </plugins>
</build>

If it prompts that the Maven plugin cannot be imported, you can modify the Maven configuration file conf/settings.xml and add the following content:

<pluginGroups>
 <pluginGroup>com.spotify</pluginGroup>
</pluginGroups>

Then

insert image description here

Note that when importing dependencies, you must first import the dependent packages - do not configure the configuration tag first.

3. Add IDEA startup configuration

insert image description here

or

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

docker run -d -p 8761:8761 --name eureka01 image_name
docker logs -f container_name

7. Push the Docker image of the local server to the Alibaba Cloud private warehouse

1. Create an Alibaba Cloud image repository

insert image description here
insert image description here
insert image description here
insert image description here

2. Push your image to the image repository

insert image description here

Just follow the operation guide.

8. Create a local image repository

1. Create a new local warehouse

The local warehouse is also a docker container

docker pull registry

vim /usr/lib/systemd/system/docker.service
========================================================================
Find the Service node and add a new parameter at the end of the ExecStart attribute with the value:
--insecure-registry 192.168.74.131:5000

vim /etc/docker/daemon.json
=========================================================================
Add the following configuration at the end:
{
"insecure-registries":["192.168.74.131:5000"]
}

systemctl daemon-reload
systemctl restart docker

docker run -p 5000:5000 -v /opt/registry:/var/lib/registry --name registry -d registry

192.168.74.131 refers to the local business server address.

2. Browse to view the local warehouse

http://ip:5000/v2

3. Push the image

# Rename the image docker tag [ImageId] ip:5000/[image name]:[image version number]
docker push ip:5000/[image name]:[image version number]

View push results in the browser
http://ip:5000/v2/_catalog

4. Pull the image

docker pull ip:5000/[image name]:[image version number]

This is the end of this article about the use of Docker under CentOS8. For more information about the use of Docker under CentOS8, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to view files in Docker image
  • How to modify the contents of an existing Docker container
  • docker logs - view the implementation of docker container logs

<<:  MySQL master-slave replication principle and points to note

>>:  Solution to Vue's inability to watch array changes

Recommend

The magic of tr command in counting the frequency of English words

We are all familiar with the tr command, which ca...

Essential Handbook for Web Design 216 Web Safe Colors

The color presentation on a web page will be affec...

Solution to Docker disk space cleaning

Some time ago, I encountered the problem that the...

Implementation of vscode custom vue template

Use the vscode editor to create a vue template, s...

Summary of some practical little magic in Vue practice

How can you forget lazy loading of routes that al...

JavaScript functional programming basics

Table of contents 1. Introduction 2. What is func...

Html sample code for reading and displaying pictures in a local folder

One purpose Select a local folder on the Html pag...

A brief discussion on several situations where MySQL returns Boolean types

mysql returns Boolean type In the first case, ret...

How to optimize MySQL indexes

1. How MySQL uses indexes Indexes are used to qui...

Vue3 AST parser-source code analysis

Table of contents 1. Generate AST abstract syntax...

Summary of common problems and solutions in Vue (recommended)

There are some issues that are not limited to Vue...

Optimize MySQL with 3 simple tweaks

I don't expect to be an expert DBA, but when ...

Advanced Usage Examples of mv Command in Linux

Preface The mv command is the abbreviation of mov...

Example code for CSS to achieve horizontal lines on both sides of the text

This article introduces the sample code of CSS to...