首页 > 编程知识 正文

docker设置自启动,docker 自启动服务

时间:2023-05-04 23:31:56 阅读:185254 作者:831

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的看这里。

# step 1: 卸载旧版本,安装必要的一些系统工具sudo apt-get remove docker docker-engine docker.io containerd runcsudo apt-get updatesudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common# step 2: 安装GPG证书curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -# Step 3: 写入软件源信息sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"# Step 4: 更新并安装Docker-CEsudo apt-get -y updatesudo apt-get -y install docker-ce# 安装指定版本的Docker-CE:# Step 1: 查找Docker-CE的版本:# apt-cache madison docker-ce# docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages# docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages# Step 2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.1~ce-0~ubuntu-xenial)# sudo apt-get -y install docker-ce=[VERSION]

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

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

安装最新稳定版本docker

# step 1: 安装必要的一些系统工具sudo yum install -y yum-utils device-mapper-persistent-data lvm2# Step 2: 添加软件源信息sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# Step 3: 更新并安装Docker-CEsudo yum makecache fastsudo yum -y install docker-ce# Step 4: 开启Docker服务sudo service docker start# 注意:# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。# vim /etc/yum.repos.d/docker-ee.repo# 将[docker-ce-test]下方的enabled=0修改为enabled=1## 安装指定版本的Docker-CE:# Step 1: 查找Docker-CE的版本:# yum list docker-ce.x86_64 --showduplicates | sort -r# Loading mirror speeds from cached hostfile# Loaded plugins: branch, fastestmirror, langpacks# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable# docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable# docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable# Available Packages# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)# sudo yum -y install docker-ce-[VERSION]

查看版本:

[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

参考地址:https://www.awaimai.com/665.html

http://guide.daocloud.io/dcs/docker-9152677.html

https://help.aliyun.com/document_detail/60742.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。