ubuntu16.04安装docker

首先注意看官方的参考文档: https://docs.docker.com/engine/installation/linux/ubuntulinux/

原有的一种安装方式:

curl -sSL https://get.docker.com/ | sudo sh
现在貌似不提供了。。

由于官方文档变化频繁,如果安装方式与本文有差异以官方文档为准

查看内核版本,docker对内核版本有要求,ubuntu16.04肯定符合,这一步可以略过

$ uname -r
结果
4.4.0-47-generic

更新源,确保APT以https的方式工作,并且安装了CA证书
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates

导入gpg密钥
$ sudo apt-key adv \
               --keyserver hkp://ha.pool.sks-keyservers.net:80 \
               --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

添加docker源,其它版本添加请参照官方文档,官方只提供LTS版本的源
找到对应版本的源地址,16.04对应到源地址为
deb https://apt.dockerproject.org/repo ubuntu-xenial main


执行命令添加源
$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list

更新源
$ sudo apt-get update



查看可安装列表(这步可以略过)
$ apt-cache policy docker-engine

结果
docker-engine:
  已安装:(无)
  候选: 1.12.3-0~xenial
  版本列表:
     1.12.3-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.2-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.1-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.0-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.2-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.1-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.0-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages


安装 默认安装最近的版本
$ sudo apt-get install docker-engine

启动
$ sudo service docker start


运行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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

如果出现网络问题无法下载,就先从网易蜂巢的镜像市场到hello-world运行

docker run hub.c.163.com/library/hello-world
或者先pull后run

docker pull hub.c.163.com/library/hello-world:latest



以非管理员权限运行(每次运行要加sudo也不是事,对吧)
创建docker用户组(默认已经创建)
$ sudo groupadd docker

将当前用户加到这个组里
(不用改$USER这几个字,$USER这个环境变量就是指当前用户名)
$ sudo usermod -aG docker $USER

再尝试运行
$ docker run hello-world

如果运行出现

Cannot connect to the Docker daemon. Is the docker daemon running on this host?
官方文档提示你设置环境变量,其实没什么用,从网上看到很多结果都是无意中突然好了。。。

事实上是因为加入用户组这个东西必须注销或重启才能生效,你注销或者重启一下马上就好了。


附:常用命令

docker version #查看版本  
docker images #查看镜像列表  
docker images -a  #查看镜像列表  
docker rmi -f [镜像id]  #删除指定镜像







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值