docker在linux中的安装

1、准备
系统要求CentOS 7.X 以上版本,内核至少3.10,64-bit

1.1、使用 uname -r 检查 kernel (内核)版本

[root@localhost ~]# uname -r
 3.10.0-693.5.2.el7.x86_64

1.2、设置阿里CentOS仓库为了更新插件/软件包时更加流畅

步骤一:执行下面命令下载CentOS-7镜像仓库,以CentOS-Base.repo名字保存在/etc/yum.repos.d/目录下。

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

步骤二:执行下面命令,将服务器上的软件包信息先在本地缓存,以提高搜索安装软件的速度。

[root@localhost ~]# yum makecache

步骤三:执行下面命令更新软件包

[root@localhost ~]# yum update

1.3、添加 yum 仓库

[root@localhost ~]#sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

2、安装
2.1、安装docker

[root@localhost ~]# sudo yum install docker-engine

2.2、启动docker服务

[root@localhost ~]# sudo systemctl enable docker.service

2.3、启动docker守护

[root@localhost ~]# sudo systemctl start docker

3、验证

[root@localhost ~]# sudo docker run hello-world

Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

整个过程是这样的:

Docker 客户端连接到 Docker 守护进程;
Docker 守护进程从 Docker Hub 中拉取名为 “hello-world” 的 image(镜像);
Docker 守护程序从该 image 中创建新的容器,该容器执行输出动作,输出的内容就是上面所看到的;
Docker 守护程序将输出流到 Docker 客户端并发送你的终端显示。

4、查看docker image

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              f2a91732366c        3 weeks ago         1.85kB

以上就完了docker在CentOS中的安装和启动

猜你喜欢

转载自blog.csdn.net/ligh_sqh/article/details/80755083