Install docker under linux

install docker

Method 1: Install docker offline

Link: https://pan.baidu.com/s/1s1lhCLlmbZk0NpFuw2sySA
Extraction code: ss9h

Method 2: Install docker automatically on the network

Docker official and domestic daocloud both provide one-click installation scripts, making Docker installation more convenient.

The official one-click installation method:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

Domestic daocloud one-key installation command:

curl -sSL https://get.daocloud.io/docker | sh

Execute any of the above commands and wait patiently to complete the Docker installation.

Method 3: Manually install docker on the Internet

docker installation document
docker before uninstalling the system

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

Install Docker-CE
to install necessary dependencies

sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Verify that the installation was successful

start docker

sudo systemctl start docker

Verify that Docker Engine-Community is installed correctly by running the hello-world image.

// 拉取镜像
sudo docker pull hello-world
// 执行hello-world
sudo docker run hello-world

Set up autostart

sudo systemctl enable docker

Configure docker image acceleration

# 创建目录
sudo mkdir -p /etc/docker
# 配置镜像加速器地址
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://hl1kipsc.mirror.aliyuncs.com"]
}
EOF
# 重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker

uninstall docker

stop docker

systemctl stop docker

View the docker file package installed by yum

yum list installed |grep docker

[root@localhost ~]# yum list installed |grep docker
containerd.io.x86_64                    1.6.9-3.1.el7                  @docker-ce-stable
docker-ce.x86_64                        3:20.10.21-3.el7               @docker-ce-stable
docker-ce-cli.x86_64                    1:20.10.21-3.el7               @docker-ce-stable
docker-ce-rootless-extras.x86_64        20.10.21-3.el7                 @docker-ce-stable
docker-compose-plugin.x86_64            2.12.2-3.el7                   @docker-ce-stable
docker-scan-plugin.x86_64               0.21.0-3.el7                   @docker-ce-stable

Delete the yum installation package queried in the previous step:

yum remove containerd.io.x86_64   

Delete images, containers, configuration files, etc.:

rm -rf /var/lib/docker

Verification delete successful

docker -v

docker basic commands

docker command

# 查看docker版本号
docker -v
# 启动docker
sudo systemctl start docker
# 查看docker状态
sudo systemctl status docker
# 关闭docker
sudo systemctl stop docker
# 搜索仓库镜像
docker search 
# 拉取镜像:
docker pull 镜像名
# 查看正在运行的容器:
docker ps
# 查看所有容器:
docker ps -a
# 删除容器:
docker rm container_id
# 查看镜像:
docker images
# 删除镜像:
docker rmi image_id
# 启动(停止的)容器:
docker start 容器ID
# 停止容器:
docker stop 容器ID
# 重启容器:
docker restart 容器ID
# 查看容器日志
docker logs 容器id
# 重启容器
docker restart 容器名称

Install software using docker

docker install mysql

Download mysql5.7 image

# docker pull mysql:版本号
docker pull mysql:5.7

Create an instance and start
Parameter Description
-p 3306:3306: Map port 3306 of the container to port 3307 of the host Note that in order to prevent port conflicts, change it to port 3307
-v /mydata/mysql/conf:/etc/mysql: Configure the folder Mount to the host, so modifying the files under /etc/mysql is equivalent to modifying the configuration file in dockers
-v /mydata/mysql/log:/var/log/mysql: mount the log folder to the host
-v / mydata/mysql/data:/var/lib/mysql/: Mount the configuration folder to the host
-e MYSQL_ROOT_PASSWORD=root: Initialize the password of the root user as root

docker run -p 3307: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

insert image description here

insert image description here

Enter the mysql container of dockers

docker exec -it mysql /bin/bash

Check the MySQL installation location
The configuration file is under /etc/mysql
The log file is under /var/log/mysql

 whereis mysql

Modify the MySQL configuration in docker in Linux

初始  /mydata/mysql/conf/ 下没有my.cnf文件, vi 命令会自动创建一个my.cnf文件
vi /mydata/mysql/conf/my.cnf

Copy the following content into the my.cnf file and save
it. skip-name-resolve is to skip domain name resolution and solve the problem of slow mysql connection

[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

Restart the mysql container

docker restart mysql

into the container again

# 进入容器
docker exec -it mysql /bin/bash
# 查看容器内配置文件挂载情况, 和linux中一样说明挂载成功
cat /etc/mysql/my.cnf 

Set root remote access
Execute the following command, and use navicat to connect to the database, user name: root, password: root

# 在linux 中登录 docker中的mysql
docker exec -it mysql mysql -uroot -proot
# 设置远程访问权限
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
# 刷新配置
flush privileges;

Set the mysql container to start automatically at boot

sudo docker update mysql --restart=always

docker install reids

Download mirror file

docker pull redis

Create an instance and start

# 在linux中创建redis挂载文件目录
mkdir -p /mydata/redis/conf
# 创建挂载文件
touch /mydata/redis/conf/redis.conf
# 实例化一个redis容器
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
# 在linux中连接redis客户端 
docker exec -it redis redis-cli

The redis installed above is not persistent, configure redis persistence

# 编辑linux中挂载的redis配置文件
vi /mydata/redis/conf/redis.conf
# 设置redis持久化
appendonly yes
# 重启redis容器
docker restart redis

Set the redis container to start automatically at boot

sudo docker update redis --restart=always

Install redis visualization tool
Link: https://pan.baidu.com/s/1PN7WHpzDYd5cxukwLwhiiw
Extraction code: ukkc

Guess you like

Origin blog.csdn.net/qq_44154912/article/details/126446604