docker centos7下的安装与卸载

centos7 docker安装、卸载

  • 安装
    • 卸载旧的docker
    • 安装Docker Engine - Community
    • 执行安装命令
    • 启动、关闭、重启docker服务
    • 查看docker版本
    • 为docker配置镜像加速
    • 通过运行hello-world镜像验证是否正确安装
  • 快捷安装
  • 卸载
    • 1. 卸载docker包
    • 2. 删除所有镜像,容器和卷:

安装

你可以直接进入官方文档进行阅读

卸载旧的docker

[root@kane ~]# yum remove docker \
				              docker-client \
				               docker-client-latest \
				               docker-common \
				               docker-latest \
				               docker-latest-logrotate \
				               docker-logrotate \
				               docker-engine

安装Docker Engine - Community

[root@kane ~]# yum install docker-ce docker-ce-cli containerd.io

执行安装命令

[root@kane ~]# yum install -y epel-release
[root@kane ~]# yum install docker-ce docker-ce-cli containerd.io

启动、关闭、重启docker服务

[root@kane ~]# systemctl start docker
[root@kane ~]# systemctl stop docker
[root@kane ~]# systemctl restart docker

查看docker版本

[root@kane ~]# docker version
Client:
 Version:           18.09.7
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        2d0083d
 Built:             Thu Jun 27 17:56:06 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.7
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       2d0083d
  Built:            Thu Jun 27 17:26:28 2019
  OS/Arch:          linux/amd64
  Experimental:     false

为docker配置镜像加速

在国内使用docker速度可能会较慢,还需配置国内镜像加速

现有如下国内镜像

  • Docker 官方中国区 https://registry.docker-cn.com
  • 网易 http://hub-mirror.c.163.com
  • ustc https://docker.mirrors.ustc.edu.cn

永久配置docker镜像加速

使用vim /etc/docker/daemon.json 命令修改\创建文件并添加如下信息

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

也可以直接拉取指定仓库

[root@kane home]# docker pull docker.mirrors.ustc.edu.cn/library/mysql

通过运行hello-world镜像验证是否正确安装

[root@kane ~]# 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@kane ~]# curl -fsSL https://get.docker.com -o get-docker.sh
[root@kane ~]# sh get-docker.sh

警告:

  • 不建议在生产环境中使用这些脚本
  • 在本地运行脚本之前,一定要检查从internet下载的脚本。

卸载

卸载docker非常简单,你只需要两步即可完成

1. 卸载docker包

[root@kane ~]# yum remove docker-ce

2. 删除所有镜像,容器和卷:

[root@kane ~]# rm -rf /var/lib/docker

你可能感兴趣的:(docker和k8s学习)