preface

Docker operation image

First, the image name is generally divided into two parts:[repository]:[tag], the former is the mirror name, the latter is the version number. When no tag is specified, the default is latest, which represents the latest version.

1. Pull the mirror

How do you get the mirror image in the first place? You can build an image locally using the Docker build command. Later we will talk about how to build your own image. First we pull the image from the image repository and use the Docker pull command to pull the image, as shown below:

docker pull nginx
Copy the code

First we need to find the docker image repository, website: hub.docker.com/, enter the name of the image you want to pull, as shown below, we pull a Nginx to install.

After retrieval, we select a version we need to download:

2. View the mirror

After we pull the image successfully (download successfully), how to view our image? Use the Docker images command to view the image we just pulled, as shown below:

docker images
Copy the code

3. Delete the mirror

The list lists the existing mirror, for example, we do not need this mirror, how to delete it? Use the docker RMI command, as shown below:

docker rmi nginx
Copy the code
Docker RMI image name/DOCker RM image IDCopy the code

4. Save the image

What if our image needs to be shared with others? To use docker push, we need to have an image file first. In fact, it is similar to sharing the file. We need to process it into a compressed package, which can be packaged into a tar file using the Docker Save command. Then how to decompress the image when others receive it? Use the docker load command to decompress, as shown in the following figure:

Image packaging:

docker save -o nginx.tar nginx:latest
Copy the code

Before this, we first delete the mirror, and then do the import operation, so as not to repeat.

5. Read the mirror

Image decompression:

Run the following command to decompress the tar package:

docker load -i nginx.tar
Copy the code

5. Mirror help command

What if I can’t remember so many commands? Use the Docker help command to help us see how each command is used, as shown in the following figure:

docker help
Copy the code

Continue with the docker –help command to see how the command is used:

docker images --help
Copy the code

Docker container basic operations

1. Create and run the container

docker run --name mynginx -p 80:80 -d nginx
Copy the code

Docker run: Creates and runs a container

–name: Give the container a name

-p: Maps the host port to the container port. The host port is on the left of the colon, and the container port is on the right

-d: indicates that the process is running in background mode

Nginx: full name of the image, no label, representing the latest version

2. View the running status of the container

docker ps -a
Copy the code

3. View the container startup log

Docker logs container nameCopy the code

If you want to view real-time log information, trace log output:

Docker logs -f Container nameCopy the code

4. Stop the container

Docker stop Container IDCopy the code

When the container status is Exited (0), the container exits. When the container status is Up, the container is online

5. Start the container

Docker start Container IDCopy the code

6. Pause the container

Docker Pause container IDCopy the code

7. Restore the container

Docker ID of an unpause containerCopy the code

8. Enter the container

Enter the container and modify the HTML welcome page of Nginx.

docker exec -it mynginx bash
Copy the code

exit// Exit the terminalCopy the code

9. Delete the container

Docker RM Container IDCopy the code

Before deleting a container, you must stop the container before you can execute the delete command:

Docker container data volume operation

1. Data volume basic commands

A data volume is a virtual directory that points to a file directory in the host file system

1.1 Creating a Data Volume

docker volume create html
Copy the code

1.2 Viewing Data Volumes

docker volume inspect
Copy the code
docker volume ls
Copy the code

1.3 Deleting a Data Volume

Docker Volume prune // Delete an unused data volumeCopy the code
Docker volume rm HTML // More data volume name deletedCopy the code

2. Mount the data volume

To change the default welcome page for Nginx startup, we use the data volume mount method:

docker run --name mynginx -p 80:80 -v html:/usr/share/nginx/html -d nginx
Copy the code

-v: Mount the HTML data volume to /usr/share/nginx/html. If the HTML data volume does not exist, the container will automatically create the HTML data volume

Now that nginx has started successfully, we go to check whether the HTML data volume has been created successfully.

Go to the hard disk storage address of the data volume and modify the HTML content of Nginx.

Let’s change the Nginx welcome page:

Modify save successful, we refresh the web page, found dynamic refresh, advanced, cool !!!!!!!!!!!! .

Dockerfile custom image

Here we deploy a JAR file as an example, a brief description of the use of Dockerfile, first prepare a common SpringBoot JAR package, and upload to the Linux server.

1, write Dockerfile file

# Docker image for springboot file run
# VERSION 0.0.1
# Author: DT Chen Bai
FROM java:8
MAINTAINER [email protected]
LABEL description="Describe jar package information"
ADD dt.jar app.jar 
ENTRYPOINT ["java"."-jar"."app.jar"]
Copy the code

Command explanation:

JDK is the core of the whole Java, is the basic environment for Java to run, so first must have the base image Java, here: Indicates the version. If no TAG is specified in the image name, the latest is used by default.

MAINTAINER: MAINTAINER information, usually in name/email format.

LABEL: Used to add metadata to an image, similar to remarks.

WORKDIR: working directory, similar to the CD command

ADD: ADD a jar package to the container and rename it app.jar.

RUN is an image operation command, such as a special configuration or installation command. By default, the RUN command uses /bin/sh, Shell, and root permission. If the command is too long and needs a line break, add \ to the end of the line.

ENTRYPOINT: is the container start command.

2. Build an image

Note that. Indicates that Dockerfile is in the current directory

docker build -t boot-service .
Copy the code

3. Run the image

Docker run -d -p 8080:9093 boot-service -d is used to run the container in the background. -p is used to map port 8080 in the server to port 9093 in the containerCopy the code

4. Access tests

Enter the web address in the browser and access the test. Here is a small local demo to use freely. SpringBoot integrates simple use of Freemarker.

Tracking real-time logs:

conclusion

The latest edition of Spring Cloud Alibaba micro-service architecture -Sentinel high Availability protection component will be released soon. I hope you can have a try. Besides, I have built a background management system before, and I am in the process of code reconstruction, integrating Activiti workflow. Everyone can look forward to once, in a word without the support of friends, later will be more and more dry, and will give you the overall principle, as a new generation of migrant workers, how should we improve our technology, here small make up themselves to create a communication group, interested students can join, group no. In CSDN blog page you can see, we chat together, No matter front end or back end, operation and maintenance are welcome.

At the end of this article, we will continue to further study the use of other components of micro-services and the analysis of the principle. It is not easy to create, please pay attention to xiaobai CSDN: blog.csdn.net/qq_41107231 and dig gold: juejin.cn/user/394024…