更新包索引
sudo apt-get update
安装一些包使apt能够通过HTTPS使用repository
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
添加Docker官方GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88
输出内容是:
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
设置stable版本的repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
安装stable版本
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
验证安装结果
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.
(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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
表明安装成功。
下面是一些使用操作。
解决每次使用Docker需要使用sudo
的问题
方法是创建一个docker
组并把你的用户加进去
创建docker
用户组
sudo groupadd docker
把你的用户加到docker
组里面
sudo usermod -aG docker $USER
登出再登陆,使用这些设置起效
验证可以不用sudo
来运行docker
docker run hello-world