Ubuntu 18.04中安装Docker
Docker是云原生的基石,服务软件都可以包含到Docker容器中,服务软件之间相互隔离。云原生时代,几乎到了“没有服务可以脱离Docker容器”。
服务器使用Ubuntu Server 18.04,后续安装其他软件与维护都比较方便。
sudo apt-get update
sudo apt-get install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
修改 Docker driver,符合K8S等使用场景:
sudo nano /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
运行Hello World:
$ sudo docker run --rm hello-world
...
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
添加当前用户到Docker用户组,避免每次执行需要sudo:
sudo usermod -aG docker $USER
# logout, then login again
dock images