主要讲解如何在服务器中安装Docker。Docker分为两个版本:Docker CE (社区版),Docker EE (企业版)。
简而言之,一个是开源免费版本,一个是闭源收费版本。这里主要介绍免费版本的安装。
[root@iZuf652exfq23jsos943m5Z ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
直到输出:Complete! 为止。
[root@iZuf652exfq23jsos943m5Z ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
直到输出如下信息:
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@iZuf652exfq23jsos943m5Z ~]#
就代表我们配置完毕了。
[root@iZuf652exfq23jsos943m5Z ~]# yum makecache fast
刷新完毕之后会输出:(具体的根据大家的环境不同,会输出的内容是不一样的哦。但是要注意:docker-ce-stable 字段就代表我们的配置成功了)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/7/x86_64/primary_db | 82 kB 00:00:00
Metadata Cache Created
直到最后:Metadata Cache Created 就代表刷新完成了。
[root@iZuf652exfq23jsos943m5Z ~]# yum -y install docker-ce
然后系统就会进入安装模式了。整个安装过程时间会稍微长一会。(具体的速度根据服务器下载各种依赖库的时长决定)
直到最后输出:Complete! 就代表安装完毕了。
[root@iZuf652exfq23jsos943m5Z ~]# systemctl start docker
[root@iZuf652exfq23jsos943m5Z ~]#
我们如果想停止,就是输入:systemctl stop docker。如果想查询状态就输入 systemctl status docker。
更多的systemctl命令,可以通过网络进行搜索。这里就不扩展介绍了
Docker的默认官方远程仓库为:hub.docker.com,国内访问速度较慢。需要配置为国内镜像服务地址。
首先,创建一个docket文件夹,然后再创建一个daemon.json配置文件:
[root@iZuf652exfq23jsos943m5Z ~]# mkdir -p /etc/docker
[root@iZuf652exfq23jsos943m5Z ~]# vim /etc/docker/daemon.json
然后在文件中配置:
{
"registry-mirrors": ["https://kqh8****.mirror.aliyuncs.com"]
}
里面的配置链接,根据https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 获取的加速器地址。
配置完毕之后,执行刷新配置文件:
[root@iZuf652exfq23jsos943m5Z ~]# systemctl daemon-reload
[root@iZuf652exfq23jsos943m5Z ~]#
然后重启服务生效:
[root@iZuf652exfq23jsos943m5Z ~]# systemctl restart docker
这个时候我们就可以使用docker拉取各种镜像了。
例如拉取nginx的镜像:
[root@iZuf652exfq23jsos943m5Z ~]# docker search nginx
[root@iZuf652exfq23jsos943m5Z ~]# docker pull nginx:latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@iZuf652exfq23jsos943m5Z ~]#
这个时候只是将镜像拉取到本地了。
我们如果要查看本地拉取的镜像:
[root@iZuf652exfq23jsos943m5Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 9 months ago 141MB
[root@iZuf652exfq23jsos943m5Z ~]#
例如我们拉取最新的Halo 1.6.0版本
[root@iZuf652exfq23jsos943m5Z ~]# docker pull halohub/halo:1.6.0
1.6.0: Pulling from halohub/halo
cf92e523b49e: Pull complete
be4c7f172af2: Pull complete
521599bc479f: Pull complete
08fd90861fe7: Pull complete
b1ea2ac8cad0: Pull complete
8c707d1aa2bb: Pull complete
f554acbef747: Pull complete
4f4fb700ef54: Pull complete
6a5501195735: Pull complete
a9d020cd700f: Pull complete
Digest: sha256:c7626d050f308d43610afee730aef7b23804be316eb882b6cdf6c3e7cc230db3
Status: Downloaded newer image for halohub/halo:1.6.0
docker.io/halohub/halo:1.6.0
我们查询镜像就会有两个镜像了:
[root@iZuf652exfq23jsos943m5Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
halohub/halo 1.6.0 4cb8e63d2604 13 days ago 356MB
nginx latest 605c77e624dd 9 months ago 141MB
[root@iZuf652exfq23jsos943m5Z ~]#
最后,就是对镜像进行安装操作了,例如安装nginx:
[root@iZuf652exfq23jsos943m5Z ~]# docker run --name nginx-test -p 8080:80 -d nginx
1b3ba970a3388c61990542858003c08a4be78ef170ddd036b5149361e69289f0
[root@iZuf652exfq23jsos943m5Z ~]#
命令参数说明:
这个时候,我们就可以通过浏览器访问nginx了。
或者通过Docker 安装halo服务:
[root@iZuf652exfq23jsos943m5Z ~]# docker run -it -d --name halo -p 8090:8090 -v ~/.halo:/root/.halo --restart=unless-stopped halohub/halo:1.6.0
如果想了解Halo博客如何通过Docker进行安装,可以通过halo官网示例进行了解:https://docs.halo.run/getting-started/install/docker
我们如果想删除镜像,可以通过: docker rmi -f nginx 或者 docker rmi -f halo 进行删除镜像
我们如果想卸载本地安装的Docker。可以通过命令:
[root@iZuf652exfq23jsos943m5Z ~]# yum remove docker
> docker-client
> docker-client-latest
> docker-common
> docker-latest
> docker-latest-logrotate
> docker-logrotate
> docker-selinux
> docker-engine-selinux
> docker-engine
> docker-ce
就会进行卸载操作了。
页面更新:2024-04-17
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号