Initial installation and use of Docker

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable container, and then publish it to any popular Linux or Windows operating system machine. Virtualization , container It is completely using the sandbox mechanism, and there will be no interface between them.

A complete Docker consists of the following parts:

  1. DockerClient client

  2. Docker Daemon daemon process

  3. Docker Image mirroring

  4. DockerContainer container

Uninstall the docker before the system

    sudo yum remove docker\docker-client\docker-client-latest\docker-common\docker-latest\ docker-latest-logrotate\docker-logrotate\docker-engine

Install Docker-C

   Install required dependencies

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

Set the yum location of the docker repo
 

sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

 Install docker, and docker-cli

sudo yum install docker-ce docker-ce-cli containerd.io

 start docker

sudo systemctl start docker

 check docker version

docker -v

Set docker to start automatically at boot

sudo systemctl enable docker

 Configure docker image acceleration

  Execute the following four commands in sequence

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

Install mysql in docker

  Download mirror file

    

docker pull mysql:5.7

Create an instance and start

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
参数说明
-p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口
-v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂载到主机
-v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
-v /mydata/mysql/data:/var/lib/mysql/:将配置文件夹挂载到主机
-e MYSQL_ROOT_PASSWORD=root:初始化 root 

MySQL 配置
vi /mydata/mysql/conf/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
注意:解决 MySQL 连接慢的问题
在配置文件中加入如下,并重启 mysql
[mysqld]
skip-name-resolve
解释:
skip-name-resolve:跳过域名解析

docker install redis

   Download mirror file

docker pull redis

  Create an instance and start

  

mkdir -p /mydata/redis/con
touch /mydata/redis/conf/redis.conf
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf

 View docker running containers

docker ps

 restart redis

docker restart redis

connect redis

 docker exec -it redis redis-cli


 

 Set redis persistence mode

  Enter the redis configuration directory

 Modify the file to add a line of persistent AOF command

appendonly yes

Save the file and restart redis

Set to also restart redis and mysql every time the server restarts

input the command:

 sudo docker update mysql --restart=always

Guess you like

Origin blog.csdn.net/m0_51406695/article/details/126672217