Docker安装——Ubuntu16.04

原文链接:https://blog.csdn.net/rickey17/article/details/72809384
 
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
其实开源的应用,官网都有正确的安装教程(英文版),本章按照官网的教程安装。

安装仓库

安装Docker社区版仓库
 
sudo apt-get -y install 
  apt-transport-https 
  ca-certificates 
  curl
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository 
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu 
       $(lsb_release -cs) 
       stable
sudo apt-get update

1 获取Docker社区版


在Ubuntu上安装最新的Docker社区版
 
sudo apt-get -y install docker-ce
 

测试你的Docker社区版是否安装成功
sudo docker run hello-world
 
 
安装后可查看版本
 
 docker version

版本信息显示

root@ubuntu:/home/martin# docker version

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:56 2018
 OS/Arch:           linux/amd64
 Experimental:      false
Server:
 Engine:
 Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:21 2018
  OS/Arch:          linux/amd64
  Experimental:     false
 
配置镜像加速
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
安装成功如下:
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/
 

---------------------
作者:rickey17
来源:CSDN
原文:https://blog.csdn.net/rickey17/article/details/72809384
版权声明:本文为博主原创文章,转载请附上博文链接!
原文地址:https://www.cnblogs.com/Martincheng/p/9841977.html