环境
系统:ubuntu18.04
docker:19.03.5
Docker概述
推荐每个容器只运行一个进程
安装docker
1.卸载已安装的docker
sudo apt autoremove docker
sudo apt autoremove docker-engine
sudo apt autoremove docker.io
2.执行自动安装docker的脚本
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
安装成功后出现:
Client: Docker Engine - Community
.
.
.
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker dell
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
此时,docker CE 的稳定(stable)版本已经安装在系统中。
3.新建docker用户组,并将当前用户加入
sudo groupadd docker
sudo usermod -aG docker 当前用户的用户名
4.初始化docker的一些设置
官方示例:https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file
以下分别设置了docker镜像源,docker日志驱动和每个容器的日志最大值,日志文件最大数,Docker数据存储目录(默认/var/lib/docker)
sudo vim /etc/docker/daemon.json
# 写入如下内容并保存
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://registry.aliyuncs.com",
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn"
],
"log-driver":"json-file",
"log-opts": {
"max-size":"500m", "max-file":"3"}
}
"data-root":"/data/docker"
5.设置docker开机自启动,并重启docker使配置生效
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl daemon-reload
sudo systemctl restart docker
6.验证docker的启动
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