Docker learning notes

Docker learning notes

Reference: programming bad people

Reference video: https://www.bilibili.com/video/BV1ZT4y1K75K

Study time: October 27, 2021

Docker Chinese website: https://vuepress.mirror.docker-practice.com/

Docker Foundation

Overview of Docker

Installation of Docker

slightly

Docker core architecture diagram

Docker engine and image related operations

Load local image to docker warehouse

Add local image to linux virtual machine

docker load -i image file name of imported tar

Basic operations of Docker container

Basic operation of container 1

Basic operation of container 2

Packaging backup images

Docker image layering principle

Docker network configuration

Revision:

docker network create Bridge name

Use of Docker data volumes

Two ways to create data volumes

Create a read-only data volume

Data volume operation

Docker installation common services

Summary of common service installation

To install MySQL:

Port mapping + - e environment variable: password of root user in mysql + mysqldata001 data volume mapping data in mysql + mysqlconfig001 data volume mapping mysql configuration file

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=88888888 --name mysql001 -v mysqldata001:/var/lib/mysql -v mysqlconfig001:/etc/mysql mysql

To install Tomcat:

Port mapping + tomcatApps001 container volume mapping application storage location + tomcatConfig001 mapping Tomcat configuration file location

docker run -d -p 8080:8080 --name tomcat001 -v tomcatApps001:/usr/local/tomcat/webapps -v tomcatConfig001:/usr/local/tomcat/conf tomcat

To install Redis:

Port mapping + redisData001 container volume mapping data file location + start aop persistence

docker run -d -p 6379:6379 --name redis001 -v redisData001:/data redis redis-server --appendonly yes

To install ElasticSearch:

docker run -d --name elasticsearch001 -p 9200:9200 -p 9300:9300 -v esdata001:/usr/share/elasticsearch/data -v esconfig001:/usr/share/elasticsearch/config -v esplugins001:/usr/share/elasticsearch/pluges elasticsearch

Docker installation MySQL

Mapping profile

Docker installing Tomcat

Modify the configuration file in Tomcat

Docker installation Redis

Redis persistence scheme in Docker

Redis does not enable RDB by default (it thinks it is useless), but redis provides a scheme to enable AOP: - appendonly yes

Load your own configuration file to start (generally not used)

Method 1: use DockerFile

Method 2: Download Redis, take out the configuration file, put it into linux, map the data volume, and specify the configuration file at startup

Method 3: it is not necessary to put the complete configuration file, but only the modified content

For example, create an empty redis.conf, only write: bind 0.0.0.0, and start Redis as a configuration file

Principle: if there is this configuration, it will be overwritten. If not, the original configuration will be used

Operate Redis in Docker

Redis cli means running a redis client.

docker exec -it da45019bf760 redis-cli

Docker installation Nginx

Docker installation MongoDB

Docker installation ESearch

docker run -d --name elasticsearch001 -p 9200:9200 -p 9300:9300 
    -v esdata001:/usr/share/elasticsearch/data        ### Mapping data file
    -v esconfig001:/usr/share/elasticsearch/config    ### Mapping profile
    -v esplugins001:/usr/share/elasticsearch/pluges   ### Mapping plug-in  
 elasticsearch

You can also map a large folder directly

docker run -d --name elasticsearch001 -p 9200:9200 -p 9300:9300 
    -v esall001:/usr/share/elasticsearch        ### mapping
 elasticsearch

After successful installation, access port 9200 to check whether json data is returned

http://192.168.179.131:9200

Install lk word splitter

1. Start elasticsearch and configure the mapping of config in es

2. Add the lk participle to config and decompress it

3. Restart es

Docker installation Kibana

Kibana and Docker maintain version correspondence, and kibana and Docker are placed on the same bridge

Connect es at Kibana startup: specify the environment variable - e ELASTICEARCH_URL

docker run -d --name kibana -p 5601:5601 -v ELASTICSEARCH_URL=http://192.168.228.160 kibana

Kibana profile mapping, and then modify the profile

docker run -d --name kibana -p 5601:5601 -v kibanaConfig001:/usr/share/kibana/config kibana

Docker advanced

Dockerfile overview

Dockerfile D uppercase, f lowercase

Dockerfile itself is a file without the suffix of. xxx

Context / context Directory: the folder where the Dockfile is located

Each construction of Dockerfile will generate a temporary image, but it will eventually give us a final image and put the results of each execution into the buffer (– no cache will not create the buffer)

Dockerfile common commands

Reserved command for Dockerfile

Detailed explanation of Dockerfile command

Case: Transform centos to support vim

Case: Dockerfile command exercise

Dockerfile practical application

Building spring boot application with Dockerfile

Use of Docker in IDEA

Install Docker plug-in in IDEA

Open remote connection of host in IDEA

Once enabled, you can directly operate the contents of the remote host

Docker compose template

Introduction to docker compose

Installation and uninstallation

Run the following command to download the current stable version of Docker Compose:

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

To install a different version of Compose, replace 1.24.1.

curl -L https://github.com/docker/compose/releases/download/2.0.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions to binaries:

$ sudo chmod +x /usr/local/bin/docker-compose

To create a soft chain:

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test for successful installation:

$ docker-compose --version
cker-compose version 1.24.1, build 4667896b

Note: for alpine, the following dependency packages are required: py pip, python dev, libffi dev, OpenSSL dev, gcc, libc dev, and make.

Quick use

Compose command template

Recommended blog: https://blog.csdn.net/qq_36148847/article/details/79427878

Official website:

Template command summary

Template command actual use

Using env_file to solve the problem of password insecurity

depends_on implements container orchestration (the sequential startup of containers)

Several unusual commands

Compose corresponds to Docker engine version

Official website: https://docs.docker.com/compose/compose-file/compose-file-v3/

Docker and docker compose upgrades: https://www.jianshu.com/p/41acabb2a817

My system: version does not correspond

[root@localhost DockerComopse]# docker-compose -version
docker-compose version 1.24.1, build 4667896b
[root@localhost DockerComopse]# docker version
Client: Docker Engine - Community
Version:           20.10.8

Docker compose template summary

build instruction in compose

Docker compose instruction

Docker visualizer

docker pull portainer/portainer
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
docker ps 

Tags: Linux Docker Container

Posted on Thu, 28 Oct 2021 23:29:57 -0400 by mudkicker