在centos 7上部署安装docker

一、docker概述

docker资源地址

镜像(images):

docker镜像就好比是一个模板,可以通过这个模板来创建容器服务,eg:tomcat镜像====>>run ====>>tomcat01容器(提供服务),通过这个镜像可以创建多个容器(最终服务项目运行就在容器中)。

容器(container):

docker利用容器技术,独立运行一个或者一个组应用,通过镜像来创建的。
启动、停止、删除,基本命令!
目前可以把这个容器理解成一个简易的Linux系统。

仓库(repository):

仓库就是存放镜像的地方!
仓库分为共有仓库和私有仓库!
docker hub(默认是国外的)

二、docker安装

注意:本文的命令使用的是 root 用户登录执行,不是 root 的话所有命令前面要加 sudo

环境准备

1.懂一点linux的基础

2.centos 7

环境查看

 

//使用uname -r命令查看系统内核,必须是3.10以上的
[root@localhost ~]# uname -r
3.10.0-1160.80.1.el7.x86_64
复制代码
//系统版本
[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
复制代码

安装docker

复制代码
//1.更新 yum 包(使用 root 权限,生产环境中此步操作需慎重)
//yum -y update 升级所有包同时也升级软件和系统内核;
//yum -y upgrade 只升级所有包,不升级软件和系统内核
yum -y update
//2.卸载旧的docker
yum remove docker  docker-common docker-selinux docker-engine
//3.安装软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
//4.设置 yum 源
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(默认是国外的)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)
//5.查看可用版本
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
已安装的软件包
可安装的软件包
 * updates: mirrors.huaweicloud.com
Loading mirror speeds from cached hostfile
 * extras: mirrors.huaweicloud.com
docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable
//6.选择一个版本并安装
yum -y install docker-ce-18.03.1.ce
//7.启动 Docker
systemctl start docker
systemctl enable docker  设置开机自启
//8.使用docker version查看是否安装成功
[root@localhost ~]# docker version
Client:
 Version:           18.06.3-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        d7080c1
 Built:             Wed Feb 20 02:26:51 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.3-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       d7080c1
  Built:            Wed Feb 20 02:28:17 2019
  OS/Arch:          linux/amd64
  Experimental:     false
//至此,docker安装成功!!!
复制代码

测试docker

复制代码
//使用hello-world测试
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
//查看刚才下载的hello-world镜像
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              feb5d9fea6a5        14 months ago       13.3kB
//至此,docker的安装测试全部完成!恭喜大家!
复制代码
posted @   yzq_top  阅读(441)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
点击右上角即可分享
微信分享提示