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

1、学习文档

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

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

 

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

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

 

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

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

 

如下的安装步骤都须要网络的支持哦,若是实在虚拟机中安装的,注意要外网支撑哦!数组

 

2、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.app

 

官方要求系统版本: Centos 7

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

 

3、 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 官方文档 

      

4、 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.

 

5、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。

6、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

 

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

查看 docker 中的信息,好比有多少个容器啊,镜像啊之类的,具体本身看。

docker info

 

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

docker --help

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

docker <command> --help

 

8、若是你想要安装 阿里云的加速镜像

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

若是你没有阿里云帐号,是能够经过支付宝直接注册登陆的,毕竟都是一个体系的,放心用便可!

阿里云还有一个手机监控的 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 的安装与简单测试到这里就完成了!!!

 

祝各位好运!!!

祝各位好运!!!

祝各位好运!!!

 

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

相关文章
相关标签/搜索