Docker教程-01.安装docker-ce-18.06

 


参考文章:http://www.runoob.com/docker/docker-tutorial.html

1.Docker简介

1)Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源。
2)Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
3)容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app)
4)容器的性能开销极低。

2.Docker的应用场景

1)Web 应用的自动化打包和发布。
2)自动化测试和持续集成、发布。
3)在服务型环境中部署和调整数据库或其他的后台应用。
4)从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境。

3.Docker 的优点

1)简化程序:

Docker 让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,便可以实现虚拟化。
Docker改变了虚拟化的方式,使开发者可以直接将自己的成果放入Docker中进行管理。
方便快捷已经是 Docker的最大优势,过去需要用数天乃至数周的任务,在Docker容器的处理下,只需要数秒就能完成。

2)避免选择恐惧症:

Docker 镜像中包含了运行环境和配置,所以 Docker 可以简化部署多种应用实例工作。比如 Web 应用、后台应用、数据库应用、大数据应用比如 Hadoop 集群、消息队列等等都可以打包成一个镜像部署。

3)节省开支:

云计算时代到来,使开发者不必为了追求效果而配置高额的硬件,Docker 改变了高性能必然高价格的思维定势。
Docker 与云的结合,让云空间得到更充分的利用。不仅解决了硬件管理的问题,也改变了虚拟化的方式。

4.相关链接

Docker 官网:http://www.docker.com

Github Docker 源码:https://github.com/docker/docker

5.docker-ce版本简介

5.1.全称:Docker Community Edition for CentOS

5.2.docker在更新为CE和EE版本之前的最新版本为docker-1.13,在1.13的基础之上,从2017年的3月1号开始,版本的格式变为docker-YY.MM,如下:

docker-17.12.1-ce.tgz
stable版本    每个季度发行
edge版本      每个月发行

5.3.目前,Ubuntu和CentOS都支持docker的CE和EE版本,EE版本对安全方面进行了强化。

6.安装docker-ce准备

6.1.docker-ce安装方法:

1)配置docker仓库进行yum安装,升级等,官方推荐方式
2)下载RPM包手动安装,适用于没有网络的安装环境
3)源码安装,下载tgz源码包编译安装
4)使用一些集成好的安装脚本进行安装,用于测试和开发环境快速部署

6.2.软件版本

CentOS7.5_x86-64
docker-ce-18.06.1.ce

7.yum在线安装docker-ce

# 建议上午安装,晚上docker官网基本打不开

7.1.卸载旧版docker软件

# 名称一般为docker,docker-io或者docker-engine
# 卸载完成还需要查看并清理旧的docker数据目录,包含镜像,容器,网络等配置

sudo yum remove docker docker-engine docker-common \
    docker-client docker-client-latest docker-latest docker-latest-logrotate \
    docker-logrotate docker-selinux docker-engine-selinux
rpm -qa |grep docker*
ll /var/lib/docker/

7.2.配置docker的yum仓库

# 安装依赖包

yum install yum-utils lvm2 device-mapper-persistent-data -y

# 配置stable库

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

# 就是这条命令,晚上很容易不成功

# 禁用edge和test库

yum-config-manager --disable docker-ce-edge docker-ce-test
# yum-config-manager --enable docker-ce-edge docker-ce-test

# 备注:

1)yum-utils提供yum-config-manager和utility工具
2)lvm2和device-mapper-persistent-data提供devicemapper的存储驱动
3)即使不使用edge库或test库也必须安装
4)建议上午安装,如果下载超时可以手动下载然后上传到/etc/yum.repos.d/目录
5)Note: Starting with Docker 17.06, stable releases are also pushed to the edge and test repositories.
6)如果启用edge和test库,yum安装时会安装最新版的docker,一般为test测试版,如果要安装最新的稳定版需要禁用该选项

7.3.安装docker-ce

# 查看可安装的docker-ce列表

yum list docker-ce --showduplicates
# yum list docker-ce --showduplicates | sort -r    # 倒序排列

# 安装最新版docker-ce

yum install docker-ce

# 要安装指定版本docker,可以从上面的列表选择对应的版本号

yum install docker-ce-<VERSION STRING>
yum install docker-ce-18.06.1.ce-3.el7

# 附:升级docker-ce

yum -y upgrade <包名>

# 注意:

1)如果提示需要接受GPGkey,需要与以下fingerprint匹配:
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
2)安转完成会自动创建docker用户组,需要手动创建docker用户

7.4.启动docker配置开机自启动

systemctl start docker
systemctl enable docker
ps -ef |grep docker

7.5.检查确认docker是否安装成功

docker run hello-world

实例演示:

# 用docker运行一个名为hello-world的镜像,显示以下内容表示安装正确

复制代码
[root@docker-srv tools]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete 
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Status: Downloaded newer image for hello-world:latest

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/engine/userguide/

复制代码

8.离线安装docker-ce

# 使用RPM包进行安装

RPM包下载地址:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

8.1.下载docker-ce的rpm包

mkdir -p /server/tools
cd /server/tools
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm

8.2.安装docker-ce

yum install docker-ce-18.06.1.ce-3.el7.x86_64.rpm

8.3.启动docker配置开机自启动

systemctl start docker
systemctl enable docker
ps -ef |grep docker

8.4.检查docker安装的正确性

docker run hello-world

9.使用docker脚本进行安装 

# 注意:不可以用在生产环境
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

脚本内容:

复制代码
<output truncated>

If you would like to use Docker as a non-root user, you should now consider
adding your user to the “docker” group with something like:

sudo usermod -aG docker your-user

Remember to log out and back in for this to take effect!

WARNING: Adding a user to the “docker” group grants the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.

10.卸载清理docker-ce软件 

10.1.卸载docker-ce软件

yum remove docker-ce

10.2.清理docker-ce数据

rm -rf /var/lib/docker

======== 完毕,呵呵呵呵 ========

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值