Docker 是一个开源的应用容器引擎,其作用在于可以让开发者打包他们的应用甚至是系统以及依赖包到一个轻量级、可移植的容器中,然后发布到 Linux 机器(目前仅支持64位,且Linux内核是3.10以上),当然也可以实现虚拟化。该过程最直观的比喻便是:docker类似于一个app,而docker仓库则类似于应用商店,Linux机器便是用户了。
很显然,docker天然的优势在于版本控制、易于迁移和方便部署,特别适用于高密度环境以及中小型部署。
目前docker官网 提供了企业版和社区版,下面就介绍如何在centos7上部署docker。
1.检查机器内核:
[root@docker ~]# uname -r
3.10.0-862.el7.x86_64
2.卸载旧版本:
[root@docker ~]yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
如果返回下面的消息,则说明原先机器上没有装docker:
参数 docker 没有匹配
参数 docker-client 没有匹配
参数 docker-client-latest 没有匹配
参数 docker-common 没有匹配
参数 docker-latest 没有匹配
参数 docker-latest-logrotate 没有匹配
参数 docker-logrotate 没有匹配
参数 docker-engine 没有匹配
不删除任何软件包
3.安装相关依赖环境:
3.1 安装gcc
[root@docker ~]#yum -y install gcc
3.2 安装gcc-c++
[root@docker ~]#yum -y install gcc-c++
3.3 验证gcc的版本
# 如果能返回下面的信息,则说明gcc已经配置好了。
[root@docker ~]#gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
3.4 安装需要的软件包
#包括yum-utils, device-mapper-persistent-data, lvm2
[root@docker ~]#yum install -y yum-utils device-mapper-persistent-data lvm2
4.设置stable镜像仓库:
#推荐使用阿里云镜像
[root@docker ~]#yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5.更新yum软件包索引
[root@docker ~]#yum makecache fast
6.安装DOCKER CE
[root@docker ~]#yum -y install docker-ce
7.配置镜像加速
在宿主机器编辑文件。需要注意的是,网上不少教程提到编辑的是daemon.json文件,但是后续使用会报错,所以推荐conf格式的文件:
vi /etc/docker/daemon.conf
在该配置文件中加入:
#当然加入清华镜像也是可以的,本文以科大镜像为例:
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}
8.重启 docker 服务
[root@docker ~]#systemctl restart docker
9.验证安装
9.1 查看docker版本
#出现以下信息说明安装成功
[root@docker ~]# docker version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:25:41 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:24:18 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
9.2 运行实例程序
[root@docker ~]# docker run hello-world
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:
Docker Hub
For more examples and ideas, visit:
Orientation and setup
OK,enjoy自己安装的docker吧~
本文转自微信公众号:superdiao的果壳
喜欢的朋友可以去关注(关注后有福利哦~),记得先给本文点赞或者点喜欢呐!