Docker installation on Linux system

1, RockyLinux installation Docker

1. install system tools

yum install -y yum-utils device-mapper-persistent-data lvm2

2. replace Alibaba cloud docker warehouse

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3. install docker engine

yum -y install docker-ce

Problem: problems with the installed software package buildah-1:1.24.2-4 module+el8.6.0+785+d1251653. x86_ sixty-four

resolvent

yum install --allowerasing docker-ce

4. start docker and check the docker version

systemctl start docker
docker version

5. switch Alibaba cloud image warehouse

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://revuwnfw.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

2, Docker installation portal graphical management

1. pull the portainer image

docker pull portainer/portainer

2. configure and start the portal

docker run -d -p 9000:9000 \
     --restart=always \
     -v /var/run/docker.sock:/var/run/docker.sock \
     --name prtainer \
     portainer/portainer
  • -d: Background operation
  • --Restart=always: restart after startup, and restart after failure
  • -p: Mapping port
  • -v: Mount directory
  • --Name: container name

3. log in to the portal graphical interface using IP:9000

3, Docker installation Mysql5.7

1. pull mysql5.7 image

docker pull mysql:5.7.38

2. create a mounted data volume

Create mysql folders and create conf, logs, and data folders

Run basic mysql

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:5.7.38

View mysql container ID

docker ps

Copy the configuration file in the mysql container to the local

docker cp a7de80c1fbc2:/etc/mysql/mysql.conf.d/mysqld.cnf /software/mysql/conf/

Modify mysql configuration file

server-id=123456
max_allowed_packet=20M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
default-time-zone='+8:00'
log-bin=/var/lib/mysql/mysql-bin
  • Server id: MySQL service ID
  • max_allowed_packet: maximum allowable packet size in data upload
  • sql_mode: mysql syntax verification rules
  • Default time zone: default time zone setting
  • Log bin: Binlog storage address of MySQL: note that this is the address inside the container

Delete basic mysql

docker rm -f a7de80c1fbc2[container ID]

3. configure and start mysql5.7

docker run -d -p 3306:3306 \
     --restart=always \
     -v /software/mysql/conf:/etc/mysql/mysql.conf.d \
     -v /software/mysql/logs:/logs \
     -v /software/mysql/data:/var/lib/mysql \
     -e MYSQL_ROOT_PASSWORD=123456 \
     --name mysql5.7 \
     mysql:5.7.38
  • -d: Background operation
  • --Restart=always: restart after startup, and restart after failure
  • -p: Mapping port
  • -v: Mount directory
    • /etc/mysql/mysql.conf.d: configuration file directory
    • /logs: log file directory
    • /var/lib/mysql: database data directory
  • -e: MYSQL_ROOT_PASSWORD: set the password of the default account root
  • --Name: container name

4. view the mysql running configuration

  • Enter the mysql container
docker exec -it mysql5.7 /bin/bash

view the database

show databases;

View time zone

show variables like "%time_zone%";

View syntax validation rules

SELECT @@sql_mode;

Check whether Binlog is enabled

show variables like '%log_bin%';

Check whether remote connection is enabled

quse mysql;
select User,authentication_string,Host from user;

Connect to the database remotely using Navicat premium

4, Docker installation Redis

1. pull the redis image

docker pull redis:7.0.0

2. create a mounted data volume

Create redis folder, and create conf and data folders

Download the redis configuration file and upload it to the server

  • Redis official website address: https://redis.io/download/

  • Open the redis download package and copy redis Conf configuration file

  • Upload to the conf folder in the server

Modify redis Conf configuration file

#bind 127.0.0.1 -::1
daemonize no
requirepass redis123
appendonly yes
  • #bind 127.0.0.1 -::1: open the remote connection, comment out or 0.0.0.0, indicating that anyone can access it
  • Daemon: start by daemon thread
  • requirepass: redis password
  • appendonly: persistence

3. configure and start redis7.0

docker run -d -p 6379:6379 \
     --restart=always \
     -v /software/redis/conf/redis.conf:/etc/redis/redis.conf \
     -v /software/redis/data:/data \
     --name redis7 \
     redis:7.0.0 \
     redis-server /etc/redis/redis.conf \
     --appendonly yes
  • -d: background startup
  • --Restart=always: restart after startup, and restart after failure
  • -p: Mapping port
  • -v: Mount directory
    • /etc/redis/redis.conf: redis configuration file
    • /data: redis data storage
  • redis-server /etc/redis/redis.conf: start redis with the specified configuration file
  • --appendonly yes: persistent
  • --Name: container name

4. use RDM to remotely connect to Redis

5, Docker installation Nginx

1. pull nginx image

docker pull nginx:1.22.0

2. create a mounted data volume

Create nginx folders, and create conf, logs, and html folders

Running basic nginx

docker run -d -p 80:80 --name nginx nginx:1.22.0

View nginx image ID

docker ps

[the external link image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-mWpyswdK-1654160049251)(... /appdata/roaming/typora/typera-user-images/image-20220602161254948.png)]

Copy the configuration folder in the nginx container to the local

docker cp 73d6c8e86617:/etc/nginx/ /software/nginx/
mv /software/nginx/nginx/ /software/nginx/conf
docker cp 73d6c8e86617:/usr/share/nginx/html /software/nginx/html

Delete base nginx

docker rm -f 73d6c8e86617[container ID]

3. configure and start nginx

docker run -d -p 80:80 -p 443:443 \
     --restart=always \
     -v /software/nginx/conf:/etc/nginx \
     -v /software/nginx/html:/usr/share/nginx/html \
     -v /software/nginx/logs:/var/log/nginx \
     --name nginx \
     nginx:1.22.0

4. log in to the default interface of nginx using IP:80

Tags: Linux Docker Container

Posted by Dennis1986 on Fri, 03 Jun 2022 03:16:23 +0530