docker安装及自启动

来源:互联网 发布:linux下载mysql安装包 编辑:程序博客网 时间:2024/05/16 18:41

docker很火,据说是一个能够在任何平台运行的类似沙箱环境,具体原理我也还没搞懂,但完全不影响我研究的热情,先用起来再说。搜了很多,发现国内的文章,很多都不知道啥用,我直接去官网看文档了。现在写一个记录,帮助后来人。
申明:

[root@clean ~]# uname -aLinux clean.minimal 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux[root@clean ~]# cat /etc/redhat-releaseCentOS Linux release 7.3.1611 (Core)

ubutun的看这里。
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/

我的是centos 7 1611版本的系统。
我就只讲一种最适合大众的方式,我不喜欢太多方式,只会把大家搞晕,记住一种最优的就行了,当然,我这里只写我认为最优的。
首先选择版本:Docker CE 还是 Docker EE
EE:适合企业用,收费的,安全一点;
CE:免费的,适合开发。这里有我选择CE.
安装方式,我选择仓库安装,好维护,好升级。如果原来安装有老版本,请先卸载。
卸载方法,直接复制回车即可,那个\表示换行的意思。

 sudo yum remove docker \                  docker-common \                  docker-selinux \                  docker-engine

安装依赖:

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

选择稳定仓库:

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

更新仓库缓存:

sudo yum makecache fast

安装最新稳定版本docker

sudo yum install docker-ce

查看版本:

[root@clean ~]# docker -vDocker version 17.06.0-ce, build 02c1d87

或者安装指定版本,先查看版本列表:

[root@clean ~]#  yum list docker-ce.x86_64  --showduplicates | sort -r已加载插件:fastestmirror已安装的软件包可安装的软件包Loading mirror speeds from cached hostfiledocker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stabledocker-ce.x86_64            17.06.0.ce-1.el7.centos            @docker-ce-stabledocker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stabledocker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stabledocker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable

安装指定版本:

sudo yum install docker-ce-<VERSION>

开启docker服务:

 sudo systemctl start docker

测试是否能够正常运行:

[root@clean ~]# sudo docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldb04784fba78d: Pull completeDigest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74fStatus: Downloaded newer image for hello-world:latestHello 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 bashShare 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/[root@clean ~]#

看到了吧?已经正常运行了!

这里写图片描述

官方原文:https://docs.docker.com/engine/installation/linux/docker-ce/centos/

把docker服务加入启动项,虽系统启动:

systemctl enable docker.service

查看加入是否成功:

[root@clean ~]# systemctl list-unit-files |grep dockerdocker.service                                enabled

docker的卸载:

sudo yum remove docker-ce

清除docker下载的七七八八,达到卸载干净的目的:

sudo rm -rf /var/lib/docker

docker的升级,这个官方讲的太含糊,添加更新源,然后使用如下命令:

yum upgrade docker-ce

注意:官方的说法:

UPGRADE DOCKER CETo upgrade Docker CE, download the newer package file and repeat the installation procedure, using yum -y upgrade instead of yum -y install, and pointing to the new file.

是不是写的不友好?要重新下载更新包,重新原装,但是把yum -y install +<包名>替换为yum -y upgrade <包名>。我现在没有升级需求,所以还没测试,不过估计可以直接用yum更新。

[root@clean ~]# yum --hrelp已加载插件:fastestmirrorUsage: yum [options] COMMANDList of Commands:check          检查 RPM 数据库问题check-update   检查是否有可用的软件包更新clean          删除缓存数据deplist        列出软件包的依赖关系distribution-synchronization 已同步软件包到最新可用版本downgrade      降级软件包erase          从系统中移除一个或多个软件包fs             Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.fssnapshot     Creates filesystem snapshots, or lists/deletes current snapshots.groups         显示或使用、组信息help           显示用法提示history        显示或使用事务历史info           显示关于软件包或组的详细信息install        向系统中安装一个或多个软件包list           列出一个或一组软件包load-transaction 从文件名中加载一个已存事务makecache      创建元数据缓存provides       查找提供指定内容的软件包reinstall      覆盖安装软件包repo-pkgs      将一个源当作一个软件包组,这样我们就可以一次性安装/移除全部软件包。repolist       显示已配置的源search         在软件包详细信息中搜索指定字符串shell          运行交互式的 yum shellswap           Simple way to swap packages, instead of using shellupdate         更新系统中的一个或多个软件包update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your systemupdateinfo     Acts on repository update informationupgrade        更新软件包同时考虑软件包取代关系version        显示机器和/或可用的源版本。

到这里,docker安装及自启动就讲完了,这是最容易的一种方式了。下一篇讲解如何安装rpm包!

如果线上安装失败,再尝试下载后安装:

根据你需要的docker的版本,在这里下载软件包:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

我们就直接用wget方式:

wget 包地址

安装方式:

sudo yum install /path/to/package.rpm
原创粉丝点击