Docker安装——Ubuntu16.04

本文介绍了Docker的基本概念,包括其如何帮助加快应用程序的交付速度,以及Docker的主要组件如镜像、容器和仓库等。此外,还详细描述了Docker在Ubuntu系统上的安装步骤,并提供了配置国内镜像加速的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Docker介绍

Docker是一个开源的容器引擎,它有助于更快地交付产品。Docker可将应用程序和基础设施层隔离,并且将基础设施当作程序一样进行管理。使用Docker,可以更快地打包,测试以及部署应用程序,并可以缩短从编程到部署运行代码的周期。

Docker架构

  • Docker daemon

    守护进程,运行在宿主机(DOCKER_HOST)的后台进程,可通过Docker客户端与之通信。

  • Client 
    Docker客户端时Docker的用户界面,可以接受用户命令和配置标识,并且Docker daemon通信

  • Images 
    Docker镜像是一个只读模板,包含创建Docker容器的说明。Docker镜像可以运行Docker镜像中的程序。

  • Container 
    容器是镜像的可运行实例。镜像与容器类似与面向对象中类与对象的关系。可通过Docker API或者CLI命令起停,移动,删除等。

  • Register 
    Docker Register是一个集中存储与分发镜像的服务。构建完Docker镜像后,就可在当前宿主机上运行。但如果想在其他机器上运行这个镜像,就需要手动复制。此时可以借助Docker Register避免复制。 
    一个Docker Register可以包含多个Docker仓库,每个仓库可包含多个镜像标签,每个标签对应一个Docker镜像。

安装Docker

其实开源的应用,官网都有正确的安装教程(英文版),本章按照官网的教程安装。

  1. 安装仓库

安装Docker社区版仓库

sudo apt-get -y install \
  apt-transport-https \
  ca-certificates \
  curl
  • 1
  • 2
  • 3
  • 4
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • 1
sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable"
  • 1
  • 2
  • 3
  • 4
sudo apt-get update
  • 1
  1. 获取Docker社区版

在Ubuntu上安装最新的Docker社区版

sudo apt-get -y install docker-ce
  • 1
  1. 测试你的Docker社区版是否安装成功
sudo docker run hello-world
  • 1

安装后可查看版本

xq@xq-VPCEG17YC:/etc/apt/sources.list.d$ docker version
Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Mon Mar 27 17:14:09 2017
 OS/Arch:      linux/amd64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

配置镜像加速

sudo docker run hello-world的时候可能会出现timeout,应用国内访问Docker Hub不稳定。建议改成阿里云或者DaoCloud。本节以阿里云为例。

注册阿里云账户

访问https://cr.console.aliyun.com/#/accelerator

可以获得自己的加速器 https://××××××.mirror.aliyuncs.com

echo "DOCKER_OPTS=\"--registry-mirror=https://××××××.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker

sudo service docker restart
  • 1
  • 2
  • 3

安装成功如下:

xq@xq-VPCEG17YC:/etc/docker$ echo "DOCKER_OPTS=\"--registry-mirror=https://××××××.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker
DOCKER_OPTS="--registry-mirror=https://bzf7wkv2.mirror.aliyuncs.com"
xq@xq-VPCEG17YC:/etc/docker$ sudo service docker restart
xq@xq-VPCEG17YC:/etc/docker$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
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.
 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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值