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} docker
command, and it would respond with “Adding user ** to group docker”. After that, you can use docker ps, docker images and other commands directly.