Docker 安装与使用
Ubuntu环境下Docker、Docker-compose的安装与使用,快速构建开发、学习环境。
配置软件源镜像(忽略)
# https://vuepress.mirror.docker-practice.com/install/ubuntu/
# https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# 查看ubuntu版本
$ cat /etc/os-release
# 备份并修改软件源镜像
$ cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
更新软件源
$ apt-get update
新建用户
$ adduser renlm
$ passwd renlm
用户授权
$ whereis sudoers
$ ls -l /etc/sudoers
-r--r----- 1 root root 755 Feb 3 2020 /etc/sudoers
$ chmod -v u+w /etc/sudoers
mode of '/etc/sudoers' changed from 0440 (r--r-----) to 0640 (rw-r-----)
$ vi /etc/sudoers
# User privilege specification
root ALL=(ALL:ALL) ALL
renlm ALL=(ALL:ALL) ALL
[root@JD ~]# chmod -v u-w /etc/sudoers
mode of '/etc/sudoers' changed from 0640 (rw-r-----) to 0440 (r--r-----)
检查/etc/hosts
$ vi /etc/hosts
建立 docker 用户组
$ su - renlm
$ sudo groupadd docker
将当前用户加入 docker 组
$ sudo usermod -aG docker $USER
激活对组的更改
$ newgrp docker
使用脚本自动安装
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
镜像加速器配置
# 阿里云,获取加速地址并配置
# https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [ "https://***.mirror.aliyuncs.com" ],
"log-driver": "json-file",
"log-opts": { "max-size": "500m", "max-file": "3" }
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl enable docker
$ sudo systemctl restart docker
安装docker-compose
# 配置环境变量
$ export PATH=/home/renlm/.local/bin:$PATH
$ source ~/.bashrc
# 安装pip工具
# http://mirrors.aliyun.com/pypi/
$ sudo apt-get install -y python3-pip
$ pip3 -V
$ pip3 install --user -U requests urllib3 -i https://mirrors.aliyun.com/pypi/simple
$ pip3 install --user docker-compose -i https://mirrors.aliyun.com/pypi/simple
$ docker-compose --version
镜像库
https://hub.docker.com/u/library