centos7安装docker最新入门

first 验证内核

uname -r 查看内核版本是否高于3.10 笔者的测试机器为3.10.0-862.el7.x86_64

第一个警告

切勿在没有配置docker yum' 源的情况下直接使用yum命令安装docker
由于centos7刚好满足最低内核的要求但是内核版本较低,部分功能(如 overlay2存储层驱动) 无法使用,,并且部分功能不稳定

开始安装

卸载旧版本

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

使用yum安装

执行以安装以下依赖包

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

由于网络超慢,使用国内源

# This is 中国科技大学开源镜像站
$ sudo yum-config-manager \
    --add-repo \
    https://mirrors.ustc.edu.cn/docker/linux/centos/docker-ce.repo
    
#这是官方源,不推荐
#$ sudo yum-config-manager \
#    --add-repo \
#   https://download.docker.com/linux/centos/docker-ce.repo

Optional: Enable the edge and test repositories. These repositories are included in the docker.repo file above but are disabled by default. You can enable them alongside the stable repository.(选择你需要的docker版本)

$ sudo yum-config-manager --enable docker-ce-edge

$ sudo yum-config-manager --enable docker-ce-test

You can disable the edge or test repository by running theyum-config-manager command with the --disable flag. To re-enable it, use the --enable flag. The following command disables the edgerepository.(默认禁用…执行启用…)

$ sudo yum-config-manager --disable docker-ce-edge

Note: Starting with Docker 17.06, stable releases are also pushed to the edge and test repositories.

INSTALL DOCKER CE

1.Install the latest version of Docker CE, or go to the next step to install a specific version:

# This first step means clean yum cache
$ sudo yum makecache fast
$ sudo yum install docker-ce

不想麻烦,那么试试脚本安装吧

Install using the convenience script

  • The scripts require root or sudo privileges to run. Therefore, you should carefully examine and audit the scripts before running them.
  • The scripts attempt to detect your Linux distribution and version and configure your package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to an unsupported configuration, either from Docker’s point of view or from your own organization’s guidelines and standards.
  • The scripts install all dependencies and recommendations of the package manager without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
  • The script does not provide options to specify which version of Docker to install, and installs the latest version that is released in the “edge” channel.
  • Do not use the convenience script if Docker has already been installed on the host machine using another mechanism.

This example uses the script at get.docker.com to install the latest release of Docker CE on Linux. To install the latest testing version, use test.docker.cominstead. In each of the commands below, replace each occurrence of get with test

Warning:

Always examine scripts downloaded from the internet before running them locally.

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun

Docker is installed but not started. The docker group is created, but no users are added to the group.

If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:

sudo usermod -aG docker your-user

Remember to log out and back in for this to take effect!(记住退出并返回使其生效)

Warning:

Adding a user to the “docker” group grants the ability to run containers which can be used to obtain root privileges on the docker host. Refer to Docker Daemon Attack Surface for more information.



sudo systemctl start docker
exit

Test Docker installation

docker run hello-world
#If you see the following information, congratulations
this message shows that you installation apperas to be working correctly

Uninstall Docker CE

  1. Uninstall the Docker package:
    $ sudo yum remove docker-ce
  2. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
    $ sudo rm -rf /var/lib/docker

You must delete any edited configuration files manually.

.启动 systemctl start docker
.查看状态 systemctl status docker
.查看docker信息 docker info

帮助 docker pull --help

docker基础操作

Part 1:Orientation

Welcome! We are excited that you want to learn Docker.

Docker concepts

Docker is a platform for developers and sysadmins to develop, deploy, and runapplications with containers. The use of Linux containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.

Containerization is increasingly popular because containers are:

  • Flexible: Even the most complex applications can be containerized.
  • Lightweight: Containers leverage and share the host kernel.
  • Interchangeable: You can deploy updates and upgrades on-the-fly.
  • Portable: You can build locally, deploy to the cloud, and run anywhere.
  • Scalable: You can increase and automatically distribute container replicas.
  • Stackable: You can stack services vertically and on-the-fly.

Containers and virtual machines

A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.

By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs provide an environment with more resources than most applications need.

Test docker version

Run docker --version and ensure that you have a supported version of Docker

docker --version

Docker version 18.06.1-ce, build e68fc7a

Run docker info or (docker version without --) to view even more details about your docker installation:

docker info 

Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 3
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
...

To avoid permission errors (and the use of sudo), add your user to the docker group. Read more.

Test Docker installation

验证安装

  1. Test that your installation works by running the simple Docker image, hello-world:

    docker run hello-world

    Hello from Docker!
    This message shows that your installation appears to be working correctly.

列出镜像

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值