Ubuntu 16.04安装Docker步骤

Posted jansengao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu 16.04安装Docker步骤相关的知识,希望对你有一定的参考价值。

(本文翻译自https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04)

 

添加GPG Key:

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

 

添加apt-get源

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

 

刷新apt

$ sudo apt-get update

 

查看apt对docker的下载地址,确保不是原来ubuntu的旧地址:

$ apt-cache policy docker-ce
docker-ce:
  Installed: (none)
  Candidate: 17.03.1~ce-0~ubuntu-xenial
  Version table:
     17.03.1~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.03.0~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

 

安装docker:

$ sudo apt-get install -y docker-ce

 

启动docker:

$ sudo systemctl status docker

 

检查docker运行状态:

$ sudo systemctl status docker
docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago
     Docs: https://docs.docker.com
 Main PID: 749 (docker)

 

一般来说,安装后的docker需要sudo来运行:

$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.37/containers/json: dial unix /var/run/docker.sock: connect: permission denied

 

执行以下步骤,此后就不需要sudo了。

首先,将你自己加入docker组:

$ sudo usermod -aG docker ${USER}

 

然后,令改动生效:

$ su - ${USER}

 

你也可以将其他人加入docker组:

$ sudo usermod -aG docker username

 

跑个Hello World试试:

$ docker run hello-world
Unable to find image hello-world:latest locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete 
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

Hello from Docker!

 

大功告成!

 

以上是关于Ubuntu 16.04安装Docker步骤的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu 16.04安装Docker步骤

Ubuntu 16.04安装docker详细步骤

Ubuntu 16.04安装docker详细步骤

ubuntu16.04安装docker

ubuntu16.04中docker安装curl拒绝连接问题

ubuntu16.04安装docker-compose报错及解决