一、准备环境

1、购买案例云

当然也可以自己在虚拟机中安装linux系统

购买地址:https://www.aliyun.com/activity?spm=5176.12825654.h2v3icoap.1.12b42c4a4cKlWv#/promotionArea

对于练习机而言,1核2G已经够用了。

2、设置实例安全组

设置安全组,开放端口,否则可能无法访问服务器

添加常用端口,比如80(web)、443(https)、21(ftp)、22(ssh)、3306(mysql)等。

配置好端口后,可以回到实例安全组中查看,内网入方向的配置规则情况。

3、修改远程登录密码

修改远程登录密码,然后重启服务器

4、获取公网地址

5、xshell登录服务器

二、安装docker

官网地址:https://www.docker.com/

帮助手册:https://docs.docker.com/

1、查看系统环境

docker内核必须是3.10及以上

[root@xtank ~]# uname -r
3.10.0-1062.18.1.el7.x86_64
[root@xtank ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

2、卸载老版本docker

[root@xtank ~]# yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine

3、安装依赖包

[root@xtank ~]# yum install -y yum-utils

4、设置镜像仓库

官方设置镜像仓库方法(不推荐)

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

阿里云镜像(推荐)

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

5、更新索引

[root@xtank ~]# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

6、安装docker引擎

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

7、启动docker服务

systemctl start docker

8、验证docker是否安装成功

若出现下列提示则说明安装成功了

[root@xtank ~]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

三、卸载docker

1、卸载依赖

yum remove docker-ce docker-ce-cli containerd.io

2、删除资源

rm -rf /var/lib/docker

四、配置镜像加速服务

1、Centos系统

推荐使用阿里云镜像加速服务,这里以Centos系统为例,如下:

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

五、参考

官网地址:https://www.docker.com/

帮助手册:https://docs.docker.com/

版权声明:本文为xyztank原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xyztank/articles/12945828.html