Docker Quick Start

Table of contents

1. Initial Docker

2. Basic operation of Docker

1. Mirror operation command

2. Container related commands

3. Data volume

3. Deckerfile custom image

1. Mirror structure

2. Custom mirror

四、DockerCompose


1. Initial Docker

Image (lmage) : Docker packages the application and its required dependencies, function library, environment, configuration and other files together, called image

Container (Container): The process formed after the application in the mirror is running is the container, but Docker will isolate the container, which is invisible to the outside world

docker architecture

Docker is a program of CS architecture, which consists of two parts:

Server server : Docker daemon process, responsible for processing Docker instructions, managing images, containers, etc.

Client client : Send instructions to Docker through commands or RestAPI, and can send instructions to the server locally or remotely

2. Basic operation of Docker

The image name generally consists of two parts: [repository]:[tag]

When no tag is specified, the default is latest , representing the latest version of the image

1. Mirror operation command

How to pull an nginx image from DockerHub and view it

2. Container related commands

 Create and run an Nginx container

-p is port mapping, the left is the port of the original host, and the right is the port of the container inside

Enter the Nginx container, modify the HTML file, and add text

Although exec can enter the container to modify files, it is not recommended, it is too troublesome, and the modification is not recorded

3. Data volume

If we want to solve the problem of coupling containers and data volumes, we need to use data volumes

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

It is to extract the data, bind it with the files in the original container, and store it in the hard disk of the host machine. Realizing data sharing can also prevent the data from remaining after the container disappears. The most important thing is to decouple the container from the data.

Create an nginx container and modify the index.html content in the container html directory

 Create and run an mqsql container, and hang the host directory directly to the container

Improvement: directory mount has similar syntax to data volume mount

-v[host directory]:[container directory]
-v[host file]:[container file]

The implementation idea is as follows:

1. Upload the mysqltar file in the pre-class materials to the virtual machine, and load it as a mirror image through the load command

2. Create directory /tmp/myql/data

3. Create the directory /tmp/mygl/conf, and upload the hmy.cnf file provided by the pre-class materials to /tmp/myql/conf

4. Go to DockerHub to check the information, create and run the MySQL container, and require:

  • Mount /tmp/myql/data to the data storage directory in the mysql container
  • Mount /tmp/myql/conf/hmy.cnf to the configuration file of the mysql container
  • Set MySQL password

Comparison of data volume mounting methods

The first way is to use the data volume to automatically mount, this is the default directory, the advantage is that it is automatically generated, the disadvantage is that the directory is very deep, and the rights are all handled by docker.

The second is directory mounting, creating directories and files to mount by yourself, but the trouble is that the operation is complicated to implement by yourself.

3. Deckerfile custom image

1. Mirror structure

Mirroring is to package the system function library, environment, configuration, and dependencies required by the application

Mirroring is a layered structure, each layer is called a Layer

BaseImage layer: contains basic system function library, environment variables, file system

Entrypoint: entry, which is the command to start the application in the image

Others: Add dependencies, install programs, and complete the installation and configuration of the entire application on the basis of baseImage

2. Custom mirror

Dockerfile is a text file, which contains instructions (Instructions) one by one , using instructions to explain what operations to perform to build the image. Each instruction forms a Layer.

 Build a new image based on the Ubuntu image and run a java project

Write the dockerfile first, and the red box shows the configuration base image and jdk that must be written every time a project is built. These can be extracted and extracted separately, so you don’t need to repeat it later

We can do mirroring based on this, and the above steps can be omitted. These java:8-alpine mirrors can help us do a good job

Construct:

start up:

四、DockerCompose

Docker Compose can help us quickly deploy distributed applications based on Compose files

No need to manually create running containers one by one

A Compose file is a text file that defines how each container in the cluster runs

Deploy the cloud-demo microservice cluster using dockerCompose

Guess you like

Origin blog.csdn.net/weixin_54232666/article/details/130233197