Ubuntu 16.04安装Hyperledger Fabric(一)docker安装

一、卸载旧版本的Docker

旧版本的Docker被称作docker或者docker-engine,Docker CE(社区版)包现在被叫做docker-ce。如果之前安装过了,需要先卸载:

sudo apt-get remove docker docker-engine docker.io
  • 1

二、使用存储库安装Docker

1.设置存储库:

(1).更新apt安装包索引:
sudo apt-get update
  • 1
(2).安装软件包以允许apt通过HTTPS使用存储库:
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
  • 1
  • 2
  • 3
  • 4
  • 5
(3).添加Docker官方的GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • 1

确保现在系统已经拥有密钥指纹的后八个字符串:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 
输入指令:

sudo apt-key fingerprint 0EBFCD88
  • 1

显示结果:

pub   4096R/0EBFCD88 2017-02-22
      密钥指纹 = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <[email protected]>
sub   4096R/F273FCD8 2017-02-22
  • 1
  • 2
  • 3
  • 4
(4).安装稳定版仓库:
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
  • 1
  • 2
  • 3
  • 4

2.安装Docker CE版:

(1).更新apt安装包索引:
sudo apt-get update
  • 1
(2).安装最新版的Docker CE:
sudo apt-get install docker-ce
  • 1
(3).如果不想安装最新版的Docker,可以先查看可安装版本:
apt-cache madison docker-ce
  • 1

部分输出结果:

docker-ce | 17.12.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages  
docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages  
……  
docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages  
……  
  • 1
  • 2
  • 3
  • 4
  • 5

列表的内容取决于启用了哪个存储库。第二列是Docker版本号。第三列是存储库名称,它指明了软件包来自哪个存储存储库,并通过扩展其稳定性级别。要安装特定版本,需要将本本字符串附加到包名称。

安装指令如下:

sudo apt-get install docker-ce=<VERSION>
  • 1

然后Docker守护进程就会自动启动安装了。

(4).通过运行hello-world镜像验证Docker CE已被正确安装:
sudo docker run hello-world
  • 1

这个命令下载一个测试图像并在容器中运行。容器运行时,会打印一条信息消息并退出。 
Notice:这个时候可能会出现无法连接的情况,这是由于国内访问Docker Hub不稳定。我们可以注册一个阿里云账户,获得一个专属免费的加速器地址(传送门)。然后运用下面的命令配置我们的镜像加速器:

sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
  • 1
  • 2

将以下内容写入文本:

{  
"registry-mirrors": ["自己的镜像地址"]
} 
  • 1
  • 2
  • 3

输入以下命令后注销并重新登录:

sudo systemctl daemon-reload
sudo systemctl restart docker
  • 1
  • 2

再次运行hello-world:

sudo docker run hello-world
  • 1

若出现以下信息则表明安装成功:

Unable to find image 'hello-world:latest' locally  
latest: Pulling from library/hello-world  
ca4f61b1923c: Pull complete   
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751  
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.  
    (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://cloud.docker.com/  

For more examples and ideas, visit:  
 https://docs.docker.com/engine/userguide/  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

检查版本信息:

sudo docker version
  • 1

显示信息如下:

Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:11:19 2017
 OS/Arch:   linux/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:    Wed Dec 27 20:09:53 2017
  OS/Arch:  linux/amd64
  Experimental: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

三、安装后续步骤:

1.以非root用户身份管理Docker

docker守护程序绑定到一个Unix套接字而不是TCP端口。默认情况下,Unix套接字由用户拥有root,其他用户只能使用它来访问它sudo。该docker守护进程始终运行的root用户。如果不想在运行docker命令时使用sudo,需要创建一个名为docker的Unix Group向其中添加用户。当docker守护进程启动时,它使得Unix套接字的所有权可以被docker组读/写。

要创建docker组并添加用户:

(1).创建docke组
sudo groupadd docker
  • 1
(2).将自己的用户添加到docker组中:
sudo usermod -aG docker 用户名
  • 1
(3).注销并重新登陆以重新验证组成员关系。

如果在虚拟机上进行测试,则可能需要重新启动虚拟机才能使更改生效。

sudo service docker restart
  • 1
(4).验证不需要sudo运行docker命令:
docker run hello-world
  • 1

2.配置Docker在启动时启动

sudo systemctl enable docker
  • 1

3.卸载Docker CE

(1).卸载Docker CE软件包:
sudo systemctl enable docker
  • 1
(2).删除所有图像,容器和卷:
sudo rm -rf /var/lib/docker
  • 1

4.安装docker-compose

4.1 方法一

(1).运行以下命令下载最新版本的docker-compose:
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose  
  • 1
(2).更改二进制文件的权限,使其能够运行:
sudo chmod +x /usr/local/bin/docker-compose
  • 1
(3).测试安装:
docker-compose --version
  • 4.2 方法二
  • (1)安装python-pip 软件包
  •          (可以安装aptitude工具) 
           (sudo apt-get install aptitude)然后:
  •        sudo aptitude install python-pip
  •      也可以 
  •       sudo apt-get install python-pip
  •    (2) 安装 docker-compose
  •     sudo pip install docker-compose
(4).参考文章:

参考文档:https://docs.docker.com/compose/install/#install-compose 
应用实例:https://docs.docker.com/compose/

参考文章:

https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#upgrade-docker-ce
https://docs.docker.com/engine/installation/linux/linux-postinstall/
https://yq.aliyun.com/articles/110806?spm=a2c1q.8351553.0.0.5186d9c11wgjkh
http://blog.csdn.net/rickey17/article/details/72809384
http://www.tinylab.org/use-docker-without-sudo/
  • 1
  • 2
  • 3
  • 4
  • 5
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/diligent_lee/article/details/79098302

一、卸载旧版本的Docker

旧版本的Docker被称作docker或者docker-engine,Docker CE(社区版)包现在被叫做docker-ce。如果之前安装过了,需要先卸载:

sudo apt-get remove docker docker-engine docker.io
  • 1

二、使用存储库安装Docker

1.设置存储库:

(1).更新apt安装包索引:
sudo apt-get update
  • 1
(2).安装软件包以允许apt通过HTTPS使用存储库:
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
  • 1
  • 2
  • 3
  • 4
  • 5
(3).添加Docker官方的GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • 1

确保现在系统已经拥有密钥指纹的后八个字符串:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 
输入指令:

sudo apt-key fingerprint 0EBFCD88
  • 1

显示结果:

pub   4096R/0EBFCD88 2017-02-22
      密钥指纹 = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <[email protected]>
sub   4096R/F273FCD8 2017-02-22
  • 1
  • 2
  • 3
  • 4
(4).安装稳定版仓库:
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
  • 1
  • 2
  • 3
  • 4

2.安装Docker CE版:

(1).更新apt安装包索引:
sudo apt-get update
  • 1
(2).安装最新版的Docker CE:
sudo apt-get install docker-ce
  • 1
(3).如果不想安装最新版的Docker,可以先查看可安装版本:
apt-cache madison docker-ce
  • 1

部分输出结果:

docker-ce | 17.12.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages  
docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages  
……  
docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages  
……  
  • 1
  • 2
  • 3
  • 4
  • 5

列表的内容取决于启用了哪个存储库。第二列是Docker版本号。第三列是存储库名称,它指明了软件包来自哪个存储存储库,并通过扩展其稳定性级别。要安装特定版本,需要将本本字符串附加到包名称。

安装指令如下:

sudo apt-get install docker-ce=<VERSION>
  • 1

然后Docker守护进程就会自动启动安装了。

(4).通过运行hello-world镜像验证Docker CE已被正确安装:
sudo docker run hello-world
  • 1

这个命令下载一个测试图像并在容器中运行。容器运行时,会打印一条信息消息并退出。 
Notice:这个时候可能会出现无法连接的情况,这是由于国内访问Docker Hub不稳定。我们可以注册一个阿里云账户,获得一个专属免费的加速器地址(传送门)。然后运用下面的命令配置我们的镜像加速器:

sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
  • 1
  • 2

将以下内容写入文本:

{  
"registry-mirrors": ["自己的镜像地址"]
} 
  • 1
  • 2
  • 3

输入以下命令后注销并重新登录:

sudo systemctl daemon-reload
sudo systemctl restart docker
  • 1
  • 2

再次运行hello-world:

sudo docker run hello-world
  • 1

若出现以下信息则表明安装成功:

Unable to find image 'hello-world:latest' locally  
latest: Pulling from library/hello-world  
ca4f61b1923c: Pull complete   
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751  
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.  
    (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://cloud.docker.com/  

For more examples and ideas, visit:  
 https://docs.docker.com/engine/userguide/  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

检查版本信息:

sudo docker version
  • 1

显示信息如下:

Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:11:19 2017
 OS/Arch:   linux/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:    Wed Dec 27 20:09:53 2017
  OS/Arch:  linux/amd64
  Experimental: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

三、安装后续步骤:

1.以非root用户身份管理Docker

docker守护程序绑定到一个Unix套接字而不是TCP端口。默认情况下,Unix套接字由用户拥有root,其他用户只能使用它来访问它sudo。该docker守护进程始终运行的root用户。如果不想在运行docker命令时使用sudo,需要创建一个名为docker的Unix Group向其中添加用户。当docker守护进程启动时,它使得Unix套接字的所有权可以被docker组读/写。

要创建docker组并添加用户:

(1).创建docke组
sudo groupadd docker
  • 1
(2).将自己的用户添加到docker组中:
sudo usermod -aG docker 用户名
  • 1
(3).注销并重新登陆以重新验证组成员关系。

如果在虚拟机上进行测试,则可能需要重新启动虚拟机才能使更改生效。

sudo service docker restart
  • 1
(4).验证不需要sudo运行docker命令:
docker run hello-world
  • 1

2.配置Docker在启动时启动

sudo systemctl enable docker
  • 1

3.卸载Docker CE

(1).卸载Docker CE软件包:
sudo systemctl enable docker
  • 1
(2).删除所有图像,容器和卷:
sudo rm -rf /var/lib/docker
  • 1

4.安装docker-compose

4.1 方法一

(1).运行以下命令下载最新版本的docker-compose:
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose  
  • 1
(2).更改二进制文件的权限,使其能够运行:
sudo chmod +x /usr/local/bin/docker-compose
  • 1
(3).测试安装:
docker-compose --version
  • 4.2 方法二
  • (1)安装python-pip 软件包
  •          (可以安装aptitude工具) 
           (sudo apt-get install aptitude)然后:
  •        sudo aptitude install python-pip
  •      也可以 
  •       sudo apt-get install python-pip
  •    (2) 安装 docker-compose
  •     sudo pip install docker-compose
(4).参考文章:

参考文档:https://docs.docker.com/compose/install/#install-compose 
应用实例:https://docs.docker.com/compose/

参考文章:

https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#upgrade-docker-ce
https://docs.docker.com/engine/installation/linux/linux-postinstall/
https://yq.aliyun.com/articles/110806?spm=a2c1q.8351553.0.0.5186d9c11wgjkh
http://blog.csdn.net/rickey17/article/details/72809384
http://www.tinylab.org/use-docker-without-sudo/
  • 1
  • 2
  • 3
  • 4
  • 5

猜你喜欢

转载自blog.csdn.net/u012149181/article/details/80302061
今日推荐