欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

centos7安装docker

程序员文章站 2022-06-04 18:42:52
1.官网中文安装参考手册 https://docs.docker-cn.com/engine/installation/linux/docker-ce/centos/#prerequisites 2、yum安装gcc相关 1)CentOS7能上外网 2)安装gcc [root@localhost ~ ......

1.官网中文安装参考手册

2、yum安装gcc相关

1)centos7能上外网

centos7安装docker

 

 

 2)安装gcc

[root@localhost ~]# yum -y install gcc
3)安装gcc-c++

[root@localhost ~]# yum -y install gcc-c++

图像出现如下说明安装成功!!!

centos7安装docker

 

3、如果之前安装过docker,卸载旧版本

 

 [root@localhost ~]# yum remove docker \
>                       docker-client \
>                       docker-client-latest \
>                       docker-common \
>                       docker-latest \
>                       docker-latest-logrotate \
>                       docker-logrotate \
>                       docker-engine
4、安装需要的软件包

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
5、设置stable镜像仓库

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
6、更新yum软件包索引

[root@localhost ~]# yum makecache fast
7、安装docker ce

[root@localhost ~]# yum -y install docker-ce
8、启动docker

[root@localhost ~]# systemctl start docker
9、测试

1)查看docker版本

[root@localhost ~]# docker version
client:
 version:           18.09.6
 api version:       1.39
 go version:        go1.10.8
 git commit:        481bc77156
 built:             sat may  4 02:34:58 2019
 os/arch:           linux/amd64
 experimental:      false

server: docker engine - community
 engine:
  version:          18.09.6
  api version:      1.39 (minimum version 1.12)
  go version:       go1.10.8
  git commit:       481bc77
  built:            sat may  4 02:02:43 2019
  os/arch:          linux/amd64
  experimental:     false
[root@localhost ~]#

2)运行 hello-world
[root@localhost ~]# 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:
 https://hub.docker.com/

for more examples and ideas, visit:
 https://docs.docker.com/get-started/

[root@localhost ~]#
11、配置镜像加速
1)、获取阿里云镜像加速器参考:

[root@localhost ~]#  mkdir -p /etc/docker
[root@localhost ~]# vim  /etc/docker/daemon.json
在文件中添加如下配置
#阿里云镜像加速器
#网易云

{"registry-mirrors": ["http://hub-mirror.c.163.com"] }

 #阿里云

{

  "registry-mirrors": ["https://{自已的编码}.mirror.aliyuncs.com"]

}

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
2)、配置镜像加速后重启docker可能会报错,参考:

12、卸载

[root@localhost ~]#  systemctl stop docker
[root@localhost ~]# yum -y remove docker-ce
[root@localhost ~]# rm -rf /var/lib/docker