How to install Docker in Ubuntu

翻译
2020-06-07 16:13:24
Ley Boi
870
来源:

Intro

Docker is an open source application container engine, based on Go language and following the Apache License 2.0.
Docker allows developers to package their applications and dependent packages into a lightweight, portable container, and then publish to any popular Linux machine, so it can be virtualized. 
Containers use the sandbox mechanism and have no interface between each other, which is similar to an iPhone app. The container performance cost is very low. 

1. System

The following Ubuntu versions are supported.

  • Eoan 19.10
  • Bionic 18.04 (LTS)
  • Xenial 16.04 (LTS)

2. Uninstallation

Before the installation, run the commend below to uninstall the older version.

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

3. Install Docker

Docker can be installed in several ways. Here is to install via the repository.


Update the apt package.

sudo apt-get update


The installation package allow apt to use the repository via HTTPS.

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


Add Docker official GPG key.

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


Verify the key with fingerprint.

sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown ] Docker Release (CE deb)
sub rsa4096 2017-02-22 [S]


Set up Docker repository.

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


Install Docker.

sudo apt-get install docker-ce docker-ce-cli containerd.io


Verify the installation is done.

root@ubuntu:~# sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.


4. Create a NGINX container using Docker

Run 

docker run -it nginx
to download a container.


Run 

docker ps
to check the running container.


root@ubuntu:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
165a6fb2ad38 nginx "nginx -g 'daemon of…" 2 hours ago Up 2 hours 80/tcp intelligent_herschel


Run 

docker inspect 165a6fb2ad38
to check the details of the Ngnix container.


Find the IP in 

IPAddress


and run 

curl 172.17.0.2

to check whether Nginx is running.


Run 

docker exec -it 165a6fb2ad38 bash
 to acess the container.

You can also read more tech blog







发表评论
评论通过审核后显示。