【docker 入门 - 01】- Docker 在 Centos7 上安装与测试

一、学习文档

官网网站: https://www.docker.com

中文网站:http://www.docker-cn.com

官方安装文档:https://docs.docker.com/install/linux/docker-ce/centos/

最好的文档和学习路劲,都是来自官方的一手资料!当然,文档写的不好的除外。。。

<注>:英文还能凑合的,尽量去官网安装,毕竟能够跟的上步伐!

这里的解释顺序按照普通的安装步骤走,可能会和官方顺序有点不同。

以下的安装步骤都需要网络的支持哦,如果实在虚拟机中安装的,注意要外网支撑哦!

二、OS requirements (系统要求)

To install Docker CE, you need a maintained version of CentOS 7. Archived versions aren’t supported or tested.

The centos-extras repository must be enabled. This repository is enabled by default, but if you have disabled it, you need to re-enable it.

The overlay2 storage driver is recommended.

官方要求系统版本: Centos 7

安装的 Docker 为 docker-ce,即社区版

三、 Install using the repository(指定依赖的仓库)

这里,我们可以更新一下 yum 的依赖仓库。

SET UP THE REPOSITORY(设置依赖仓库)

  1. Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.

    这里可能需要更新一下有关 yum 工具的一些依赖工具,比如 提供了 yum-config-manager (yum 配置管理)的工具 yum-utils,还有提供 设备持久化数据映射 与 1vm2 的 devicemapper 设备映射存储驱动。

更新命令如下:

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

   2. Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

     使用下面的命令来设置稳定版的仓库。

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

    3. 这里只展示安装稳定版的,如果需要更多更详细的说明,请访问 docker 官方文档 

      

四、 Uninstall old versions(卸载老旧的 docker 依赖)

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

以前的老旧的 docker 版本叫做 docker 或者 docker-engine。这里你可能需要卸载这些老旧的依赖,卸载命令如下:

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

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker CE package is now called docker-ce.

五、INSTALL DOCKER CE(安装 docker 社区版,这个足够用了)

1. Install the latest version of Docker CE, or go to the next step to install a specific version:(如果你要安装最新的 docker-ce 版本,则直接使用下面的命令,如果需要指定某个版本,则先查看第 2 条说明)

$ sudo yum install docker-ce

注: 如果这里你指定了多个 docker 仓库,则可能安装到不是稳定的版本,具体查看官网信息。一般按照上面的步骤,是没有问题的,这里只是做一下说明。

2. To install a specific version of Docker CE, list the available versions in the repo, then select and install:(想要安装某个特定版本的 docker-ce,这里会列出你想要选择的 可用版本,这里从最高版本到最低版本为 从上到下展示,命令如下:)

$ yum list docker-ce --showduplicates | sort -r

展示出来的结果可能如下:

docker-ce.x86_64            18.09.0.ce-1.el7.centos             docker-ce-stable

这是一个列表,一般会有多个版本,如果你想要安装某个特定的版本,则选择第二列,即  18.09.0.ce-1.el7.centos ,版本号为 “-” 这个短线前面的部分,比如这个的 18.09.0.ce,则安装命令如下:

这里需要指定你 docker-ce 的版本
$ sudo yum install docker-ce-18.09.0.ce

这个的原始命令为: 

$ sudo yum install docker-ce-<VERSION STRING>,其中 <VERSION STRING> 为第二列 短线 “-” 前面的部分,组合起来,就可以安装到指定版本的 docker-ce。

六、Docker 启动测试

1. 启动 Docker

$ sudo systemctl start docker

2. Verify that docker is installed correctly by running the hello-world image.(通过运行 docker 界的 hello-world,来确认我们的 docker 安装是否正确)

$ sudo docker run hello-world

如图,出现图中红框内的文字,则代表 docker 安装成功了!

3. 如果想让 docker 设置开启激动,则命令如下:

$ sudo systemctl enable docker

七、Docker 简单命令及学习指导(其实我也是个菜鸡,但我觉着大方向不会错的)

查看 docker 中的信息,比如有多少个容器啊,镜像啊之类的,具体自己看。

docker info

 学习 docker 命令,可以使用帮助命令查看手册,有什么命令不知道的,忘了的,可以通过下面的命令来查看

docker --help

 
如果想要查看某个命令的详细用法,则使用如下命令:(<command> 这个是你想要查询的某个命令)

docker <command> --help

八、如果你想要安装 阿里云的加速镜像

默认的加速镜像可能会比较慢,当然这个你可以自己决定,我用的程度也不是很深,也是借鉴别人的经验!

如果你没有阿里云账号,是可以通过支付宝直接注册登录的,毕竟都是一个体系的,放心用即可!

阿里云还有一个手机监控的 APP 哦,能直接在手机上输入命令,控制你的服务器,救急用还是挺好的,毕竟你不是时时刻刻都带着电脑到处跑吧,哈哈!

1. 在阿里云官网搜索栏中输入 “容器镜像服务”,会出现一个 “容器镜像服务 > 控制台”,直接点击进入

2. 左侧会有一个 “镜像加速器”,点击进去

3. “加速器地址” 下面的链接就是你的加速地址

4. 在 “操作文档” 一栏,选择你的系统,这里我们选择 “CentOS”

  1. 安装 / 升级 Docker 客户端,一般不用管

       2. 修改或者添加文件 /etc/docker/daemon.json

       命令如下: 

vim /etc/docker/daemon.json

内容修改为:(一看后面就像个数组,看是也是可以设置多个地址的啊,但是这里用一个就够了,多余的再说吧)

{
  "registry-mirrors": ["这里是你的加速地址哦,千万不要写我"]
}

        3. 让配置文件生效,并重启docker

sudo systemctl daemon-reload
sudo systemctl restart docker

好了,docker 的安装与简单测试到这里就完成了!!!

祝各位好运!!!

祝各位好运!!!

祝各位好运!!!

转载请注明出处 【苏子九霄】,谢谢!

猜你喜欢

转载自www.cnblogs.com/SelfCoding/p/10225602.html