简介

  Docker是dotcloud公司开源的一款产品,主要基于PAAS平台为开发者提供服务。是解决运行环境和配置问题软件容器,方便做持续集成并有助于整体发布的容器虚拟化技术。

Docker组件

  • Docker仓库:https://hub.docker.com

  • Docker Client:Docker 的客户端。

  • Docker Server:Docker daemon 的主要组成部分,接受用户通过Docker Client发出的请求,并按照相应的路由规则实现路由分发。

  • Docker镜像:Docker镜像运行之后生成容器,镜像就好比图纸,容器相当于根据图纸制作好的实物。

Docker安装

前提条件

  安装Docker,官方推荐必须需要一个CentOS7系统。该centos-extras库必须启用。默认情况下,此存储库是启用的,但是如果已禁用它,则需要重新启用它。overlay2建议使用存储驱动程序。

卸载旧版本

  1. # 全新的ContOS7精简版,没有安装过docker
  2. [root@localhost ~]# yum remove docker \
  3. docker-client \
  4. docker-client-latest \
  5. docker-common \
  6. docker-latest \
  7. docker-latest-logrotate \
  8. docker-logrotate \
  9. docker-engine
  10. Loaded plugins: fastestmirror
  11. Repository epel is listed more than once in the configuration
  12. Repository epel-debuginfo is listed more than once in the configuration
  13. Repository epel-source is listed more than once in the configuration
  14. No Match for argument: docker
  15. No Match for argument: docker-client
  16. No Match for argument: docker-client-latest
  17. No Match for argument: docker-common
  18. No Match for argument: docker-latest
  19. No Match for argument: docker-latest-logrotate
  20. No Match for argument: docker-logrotate
  21. No Match for argument: docker-engine
  22. No Packages marked for removal

安装

   官方推荐使用仓库安装docker,若不方便可选择rpm软件包或脚本安装。此次演示的为官方推荐。

设置仓库

  1. [root@localhost ~]# yum install -y yum-utils
  2. # 注意,此仓库为官方提供仓库,国内用户访问网络很坑,这里选择阿里仓库
  3. [root@localhost ~]# yum-config-manager \
  4. > --add-repo \
  5. > https://download.docker.com/linux/centos/docker-ce.repo
  6. Loaded plugins: fastestmirror
  7. adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
  8. grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
  9. repo saved to /etc/yum.repos.d/docker-ce.repo
  • 阿里仓库
  1. [root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  2. Loaded plugins: fastestmirror
  3. adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
  5. repo saved to /etc/yum.repos.d/docker-ce.repo

安装Docker引擎

  1. # 可选
  2. [root@k8s-node02 ~]# yum update
  3. # 安装Docker引擎
  4. [root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io

启动Docker

  1. [root@localhost ~]# systemctl start docker

查看状态

  1. [root@localhost ~]# systemctl status docker
  2. docker.service - Docker Application Container Engine
  3. Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  4. Active: active (running) since Sat 2020-04-11 10:15:26 CST; 15s ago
  5. Docs: https://docs.docker.com
  6. Main PID: 18129 (dockerd)
  7. Tasks: 12
  8. Memory: 46.4M
  9. CGroup: /system.slice/docker.service
  10. └─18129 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
  11. Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.935145283+08:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
  12. Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.935172947+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0 <nil>}] <nil>}" module=grpc
  13. Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.935193242+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
  14. Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.962339880+08:00" level=info msg="Loading containers: start."
  15. Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.230751040+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to...rred IP address"
  16. Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.329307123+08:00" level=info msg="Loading containers: done."
  17. Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.353432378+08:00" level=info msg="Docker daemon" commit=afacb8b graphdriver(s)=overlay2 version=19.03.8
  18. Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.353629385+08:00" level=info msg="Daemon has completed initialization"
  19. Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.381834522+08:00" level=info msg="API listen on /var/run/docker.sock"
  20. Apr 11 10:15:26 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
  21. Hint: Some lines were ellipsized, use -l to show in full.

测试

查看版本

  1. [root@localhost ~]# docker version
  2. Client: Docker Engine - Community
  3. Version: 19.03.8
  4. API version: 1.40
  5. Go version: go1.12.17
  6. Git commit: afacb8b
  7. Built: Wed Mar 11 01:27:04 2020
  8. OS/Arch: linux/amd64
  9. Experimental: false
  10. Server: Docker Engine - Community
  11. Engine:
  12. Version: 19.03.8
  13. API version: 1.40 (minimum version 1.12)
  14. Go version: go1.12.17
  15. Git commit: afacb8b
  16. Built: Wed Mar 11 01:25:42 2020
  17. OS/Arch: linux/amd64
  18. Experimental: false
  19. containerd:
  20. Version: 1.2.13
  21. GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
  22. runc:
  23. Version: 1.0.0-rc10
  24. GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
  25. docker-init:
  26. Version: 0.18.0
  27. GitCommit: fec3683

helloworld

  1. # 执行三次也没有成功, 原因是下载镜像失败
  2. [root@localhost ~]# docker run hello-world
  3. Unable to find image 'hello-world:latest' locally
  4. docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
  5. See 'docker run --help'.
  6. [root@localhost ~]# docker run hello-world
  7. Unable to find image 'hello-world:latest' locally
  8. latest: Pulling from library/hello-world
  9. 1b930d010525: Pulling fs layer
  10. docker: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/fc/fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e/data?verify=1586574550-P3eY%2BuJ7zYienz1l526gNyOltTI%3D: read tcp 192.168.0.11:43826->104.18.121.25:443: read: connection reset by peer.
  11. See 'docker run --help'.
  12. [root@localhost ~]# docker run hello-world
  13. Unable to find image 'hello-world:latest' locally
  14. docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
  15. See 'docker run --help'.

配置镜像加速

  1. cat > /etc/docker/daemon.json <<-EOF
  2. {
  3. "registry-mirrors": ["https://e9vsm9qn.mirror.aliyuncs.com"]
  4. }
  5. EOF
  1. # 加载daemon配置
  2. [root@localhost ~]# systemctl daemon-reload
  3. [root@localhost ~]# systemctl restart docker

阿里镜像加速器地址(需要登录):https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

再次执行helloworld

  1. [root@localhost ~]# docker run hello-world
  2. Unable to find image 'hello-world:latest' locally
  3. latest: Pulling from library/hello-world
  4. 1b930d010525: Pull complete
  5. Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
  6. Status: Downloaded newer image for hello-world:latest
  7. Hello from Docker!
  8. This message shows that your installation appears to be working correctly.
  9. To generate this message, Docker took the following steps:
  10. 1. The Docker client contacted the Docker daemon.
  11. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  12. (amd64)
  13. 3. The Docker daemon created a new container from that image which runs the
  14. executable that produces the output you are currently reading.
  15. 4. The Docker daemon streamed that output to the Docker client, which sent it
  16. to your terminal.
  17. To try something more ambitious, you can run an Ubuntu container with:
  18. $ docker run -it ubuntu bash
  19. Share images, automate workflows, and more with a free Docker ID:
  20. https://hub.docker.com/
  21. For more examples and ideas, visit:
  22. https://docs.docker.com/get-started/

卸载Docker

  1. 卸载Docker Engine,CLI和Containerd软件包:
  1. [root@localhost ~]# yum remove docker-ce docker-ce-cli containerd.io
  1. 主机上的映像,容器,卷或自定义配置文件不会自动删除。要删除所有图像,容器和卷:
  1. [root@localhost ~]# rm -rf /var/lib/docker

Docker常用命令

帮助命令

  1. # docker版本
  2. [root@localhost ~]# docker version
  3. # docker信息
  4. [root@localhost ~]# docker info
  5. # docker帮助
  6. [root@localhost ~]# docker --help

镜像命令

  1. # 查询本地所有镜像,docker images [OPTIONS]
  2. [root@localhost ~]# docker images
  3. REPOSITORY TAG IMAGE ID CREATED SIZE
  4. hello-world latest fce289e99eb9 15 months ago 1.84kB

OPTIONS说明:-a 列出本地所有镜像 -q 只显示镜像id

  1. [root@localhost ~]# docker images -q
  2. fce289e99eb9
  1. # 在docker仓库中查找nginx镜像, docker search [OPTIONS] [镜像名字]
  2. [root@localhost ~]# docker search nginx
  3. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  4. nginx Official build of Nginx. 12958 [OK]
  5. jwilder/nginx-proxy Automated Nginx reverse proxy for docker con 1769 [OK]
  6. richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of 764 [OK]
  7. #省略

OPTIONS说明:-s [执行数值],列出start数不小于指定值的镜像

  1. [root@localhost ~]# docker search -s 100 nginx
  2. Flag --stars has been deprecated, use --filter=stars=3 instead
  3. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  4. nginx Official build of Nginx. 12958 [OK]
  5. jwilder/nginx-proxy Automated Nginx reverse proxy for docker con 1769 [OK]
  6. richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of 764 [OK]
  7. linuxserver/nginx An Nginx container, brought to you by LinuxS 102
  1. # 将镜像下载到本地, docker pull [镜像名字]:[TAG] 默认为:latest
  2. [root@localhost ~]# docker pull nginx
  3. Using default tag: latestdocker pull nginx
  4. latest: Pulling from library/nginx
  5. c499e6d256d6: Pull complete
  6. 74cda408e262: Pull complete
  7. ffadbd415ab7: Pull complete
  8. Digest: sha256:282530fcb7cd19f3848c7b611043f82ae4be3781cb00105a1d593d7e6286b596
  9. Status: Downloaded newer image for nginx:latest
  10. docker.io/library/nginx:latest
  1. # 删除本地镜像,docker rmi [OPTIONS] [镜像名字/ID]:[TAG] [镜像名字/ID]:[TAG],只能删除没有运行的镜像,-f 强制删除
  2. [root@localhost ~]# docker rmi hello-world
  3. Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 1566e1e530c4 is using its referenced image fce289e99eb9
  4. [root@localhost ~]# docker rmi -f hello-world
  5. Untagged: hello-world:latest
  6. Untagged: hello-world@sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
  7. Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e
  1. # 删除全部本地镜像
  2. [root@localhost ~]# docker rmi -f $(docker images -qa)
  3. Untagged: nginx:latest
  4. Untagged: nginx@sha256:282530fcb7cd19f3848c7b611043f82ae4be3781cb00105a1d593d7e6286b596
  5. Deleted: sha256:ed21b7a8aee9cc677df6d7f38a641fa0e3c05f65592c592c9f28c42b3dd89291
  6. Deleted: sha256:8a305f371a6c3c445a1dfc500c1364743868a269ab8cdaf95902692e82168352
  7. Deleted: sha256:d079ef06ec1f10a8050887365f9a940b39547ba6bcc46b16a463e740984f3223
  8. Deleted: sha256:c3a984abe8a88059915bb6c7a1d249fd1ccc16d931334ac8816540b0eb686b45

容器命令

镜像运行才会生成容器。

Docker(一):Docker安装的更多相关文章

  1. docker学习(1) 安装

    docker是啥就不多讲了,简言之就是更轻量.更牛叉的新一代虚拟机技术.下面是安装步骤: 一.mac/windows平台的安装 docker是在linux内核基础上发展而来的,无法直接运行在mac/w ...

  2. Docker实践:安装wordpress

    本文将示例如何使用Docker来安装wordpress.使用三种方法: 1.基于官方的wordpress镜像使用docker run实现: 2.基于官方的wordpress镜像使用fig命令编排工具实 ...

  3. 原创docker dcos 的安装

    原创哈,上个星期无意间发现了一个可以好东西 DC/OS https://dcos.io 这个是官网哈 然后就痛苦的折磨了一个多星期; 基本是参照到https://dcos.io/docs/1.7/ad ...

  4. Docker初步认识安装和简单实例

    前话 问题 开发网站需要搭建服务器环境,FQ官网下载软件包,搭建配置nginx,apache,数据库等.官网没有直接可用的运行版本,担心网络流传的非官方发布软件包不安全还得自行编译官方源码安装,忘记步 ...

  5. Docker系列(一)安装

    操作系统版本:Centos7 Docker版本:1.8 设置安装源 1  cat > /etc/yum.repos.d/docker.repo << -EOF 2  [dockerr ...

  6. 【Howie玩docker】-docker安装

    windows忽略,小苹果木有,所以咱只看ubuntu和centOS的吧! 参考书<Docker技术入门与实战> Ubuntu 14.04安装Docker Ubuntu 14.04版本官方 ...

  7. Docker 简介及安装

    Docker简介: 什么是Docker?将应用程序自动部署到容器 go语言开源引擎  Github地址:https://github.com/docker/docker 2013年初 dotCloud ...

  8. .NET遇上Docker - Harbor的安装与基本使用

    Harbor是一个开源企业级Docker注册中心,可以用于搭建私有的Docker Image仓库.可以实现权限控制等. 安装Harbor 首先,需要安装Docker和Docker Compose,参考 ...

  9. [Docker基础]Docker安装教程

    Install Docker Docker支持几乎所有的Linux发行版,也支持Mac和Windows. 各操作系统的安装方法可参考Docker官网. 安装环境 ubuntu 16.04 Docker ...

  10. docker基础及安装

    Docker介绍: Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制 ...

随机推荐

  1. 20201124-web方向-命令执行-RCE

    参考链接:https://www.cnblogs.com/wangtanzhi/p/12311239.html RCE: 英文全称:remote command / code execcute 分别为 ...

  2. Docker这么火爆。章节一:带你详尽了解Docker容器的介绍及使用

    前言 很多小伙伴可能在工作中都听说过Docker,但是实际工作中却没有使用过,听得多了,也对Docker内心有一种很深切的想了解,但是因为各种原因而不知道如何去了解而发愁,不要急,这篇文章带你认识Do ...

  3. Java之 循环(三)

    1. switch语句 1.1 分支语句switch语句 格式 switch (表达式) { case 1: 语句体1; break; case 2: 语句体2; break; ... default ...

  4. Java基础教程——模拟浏览器发送请求

    JAVA访问网页 分别测试使用get和post方法访问网页,可以收到服务器的请求,并写入到html文件中. import java.io.*; import java.net.*; import ja ...

  5. java类,函数传参

    1 package 传参练习; 2 //学生姓名组成的数组:指定区间和查找的名字返回此人是否存在(如果存在返回位置否则-1) 3 public class test1 { 4 public stati ...

  6. mysql 优化数据类型

    1.更小的通常更好 选择不会超过范围的最小类型 2.简单就好 例如,整型比字符操作代价更低,因为字符集和校对规则(排序规则)使字符比较比整形比较更复杂. 3.尽量避免null 如果查询中包含可为nul ...

  7. 02_启动和销毁Service

    在Application关闭后,Service仍然会运行. package com.example.servdemo; import android.app.Activity; import andr ...

  8. windows服务器下tomcat 8.0 配置远程调试

    在tomcat的bin目录下, 添加debug.txt文件, 然后输入: set JPDA_ADDRESS=9901set JPDA_TRANSPORT=dt_socketset CATALINA_O ...

  9. Python音视频开发:消除抖音短视频Logo和去电视台标的实现详解

    ☞ ░ 前往老猿Python博文目录 ░ 一.引言 对于带Logo(如抖音Logo.电视台标)的视频,有三种方案进行Logo消除: 直接将对应区域用对应图像替换: 直接将对应区域模糊化: 通过变换将要 ...

  10. 第7.20节 案例详解:Python抽象类之真实子类

    第7.20节 案例详解:Python抽象类之真实子类 上节介绍了Python抽象基类相关概念,并介绍了抽象基类实现真实子类的步骤和语法,本节结合一个案例进一步详细介绍. 一.    案例说明 本节定义 ...