美文网首页
Docker 学习之安装

Docker 学习之安装

作者: seventeencm | 来源:发表于2019-06-16 17:08 被阅读0次

前言

在Docker越来越热门的情况下,自己也打算了解Docker的知识点,故有了此系列的教程。

环境信息

Windows 10
VirtualBox
CentOS 7

因没有多余的机器,而且又懒得在windows系统中安装多一个CentOS系统,故操作都是在虚拟机中操作。

安装信息

  1. 先下载CentOS镜像CentOS-7-x86_64-Minimal-1810.iso
  2. 安装CentOS,分区配置信息如下:
目录 大小
/boot 500M
/swap 1024M
/ 5G
/home 余下

安装后执行以下操作

  1. 更新时区、同步系统时间,因我没有在安装的时候选择时区故有次步骤
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntpdate
ntpdate us.pool.ntp.org
  1. 关闭selinux
vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
# 修改后需要重启系统
  1. 安装docker 【此方式存在问题,因为通过此方式安装的不是最新版本的docker;正确的安装方法请参考官网的安装方法:Get Docker CE for CentOS
yum install -y docker

补充正确的安装方法:

#根据官网的介绍,我们将安装docker-ce版本
1、卸载旧版本:
yum remove docker \
     docker-common \
     docker-selinux \
     docker-engine
# The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved
我们之前安装的docker的镜像、容器、网络配置等信息都不会被卸载
2、安装相关工具
yum install -y yum-utils \
     device-mapper-persistent-data \
     lvm2
3、配置稳定版本的库
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
4、安装最新版本的docker
yum install docker-ce
#或者说安装指定版本
#yum list docker-ce --showduplicates | sort -r
yum install <FULLY-QUALIFIED-PACKAGE-NAME>
#example
yum install docker-ce-17.06.1.ce
  1. 配置docker阿里云加速器
#通过修改daemon配置文件/etc/docker/daemon.json来使用加速器:

"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]

#配置完成后
systemctl daemon-reload
systemctl restart docker

如何获得加速器的链接,可以参考Docker 镜像加速器

  1. 来到官网入门指南根据入门步骤进行操作
docker run hello-world
#得到如下结果
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world

9a0669468bf7: Pull complete
Digest: sha256:0e06ef5e1945a718b02a8c319e15bae44f47039005530bc617a5d071190ed3fc

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.
 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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

说明docker环境已经部署完成,而且能正确运行。

相关文章

网友评论

      本文标题:Docker 学习之安装

      本文链接:https://www.haomeiwen.com/subject/nlmgfctx.html