How to Install Docker on Ubuntu

10 篇文章 0 订阅
2 篇文章 0 订阅

Purpose

to install docker on Ubuntu 17.10, while using local aliyun mirrors for docker repository and image-accelerator.

As to Ubuntu 14.04, this article would be helpful also, except some different configurations.

Steps

1. Pre-install dependencies

install some dependencies of docker: apt-transport-https, ca-certificates, curl

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

2. Add GPG certificate
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# using mirror server at aliyun.com
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
3. Add repository
# sudo add-apt-repository \
#       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
#       $(lsb_release -cs) \
#       stable"
# using mirror server at aliyun.com
sudo add-apt-repository \
    "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu \
    $(lsb_release -cs) stable"
4. Update & Install docker-ce
sudo apt-get -y update
sudo apt-get -y install docker-ce
5. Configure Accelerator for Docker images

First, register account at aliyun.com and login, access: https://cr.console.aliyun.com/#/accelerator
Then, you can get accelerator address like this: https://xxxxxxxx.mirror.aliyuncs.com

After above, you can modify configuration file(/etc/docker/daemon.json) to enable and use the accelerator.

# sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
# As to Ubuntu 14.04, just restart service using command as follows:
# sudo service docker restart
6. Run hello-world and enjoy!

After docker restarted, you can test it by run hello-world image. It could not find the image locally for the first time, then it would search and pull from library at cloud-side(also mirror server at aliyun).

sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:
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/

Digest: sha256:xx...
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/

Enjoy your docker now ?

Addition

If you want to avoid typing ‘sudo’ everytime when you are using docker commands, you can put the current user into the docker user-group. Just run sudo gpasswd -a ${USER} dockercommand, and it would respond with “Adding user ** to group docker”. After that, you can use docker ps, docker images and other commands directly.

Reference

Docker CE 镜像源站 @ Aliyun.com

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pierre_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值