Docker教程之安装

开发环境:docker ce +64位ubuntu 16.04

注:docker 包含ce和ee版本,前者为社区版,即开源版,后者为企业版,每个节点每年750刀,这里当然介绍的是社区版啦。

一.删除旧版

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

.对于14.04版本,推荐安装aufs存储驱动。

sudo apt-get update

sudo apt-get install \
    linux-image-extra-$(uname -r) \
    linux-image-extra-virtual

对于16.04及更高的版本,linux内核包含了 OverlayFS驱动,DOCKER将默认采用overlay2存储驱动。

三.安装DOCKER CE

更新源

sudo apt-get update

安装对HTTP源的访问支持

sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common

添加DOCKER官方密钥

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

验证指纹

sudo apt-key fingerprint 0EBFCD88

这里输出

pub   4096R/0EBFCD88 2017-02-22
  Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <[email protected]>
sub   4096R/F273FCD8 2017-02-22

添加apt源

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

更新

sudo apt-get update

安装

sudo apt-get install docker-ce

到这里就安装完啦,另为docker**重点内容**也提供啦安装包,可以在这里下载: https://download.docker.com/linux/ubuntu/dists/
下载后,切换到相应目录下,执行安装即可。

sudo dpkg -i /path/to/package.deb

四.验证

运行一个容器试试:

从默认仓库拉镜像

sudo docker pull hello-world

运行容器

sudo docker run hello-world

输出

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/

成功!

注意,docker使用Unix socket代替TCP port进行链接,需要用到root权限,所以一般用户执行docker命令的时候需要前缀sudo,可以把用户加入root组,则解决。

创建docker用户组

sudo groupadd docker

添加当前用户到该组

sudo usermod -aG docker $USER

设置需要注销后重新登录才会生效,如果使用的是虚拟机,可能要重启后才会生效。

五.卸载

卸载包

sudo apt-get purge docker-ce

删除资源文件

sudo rm -rf /var/lib/docker

参考:
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
https://docs.docker.com/engine/installation/linux/linux-postinstall/

猜你喜欢

转载自blog.csdn.net/calch/article/details/78207892