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

Docker image compression and optimization operations

The reason why Docker is so popular nowadays is m...

Talk about the 8 user instincts behind user experience in design

Editor's note: This article is contributed by...

How to use Vue+ElementUI Tree

The use of Vue+ElementUI Tree is for your referen...

Mini Program implements custom multi-level single-select and multiple-select

This article shares the specific code for impleme...

About VUE's compilation scope and slot scope slot issues

What are slots? The slot directive is v-slot, whi...

HTML+CSS merge table border sample code

When we add borders to table and td tags, double ...

MySQL Basic Tutorial: Detailed Explanation of DML Statements

Table of contents DML statements 1. Insert record...

Analysis of mysql view functions and usage examples

This article uses examples to illustrate the func...

The use of v-model in vue3 components and in-depth explanation

Table of contents Use two-way binding data in v-m...

How to create a Pod in Kubernetes

Table of contents How to create a Pod? kubectl to...

Implementing login page based on layui

This article example shares the specific code of ...

Method of dynamically loading geojson based on Vue+Openlayer

Load one or more features <template> <di...

How to migrate the data directory in mysql8.0.20

The default storage directory of mysql is /var/li...