Docker安装、配置,Docker常用工具
原创大约 4 分钟...
安装 Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
安装 Docker
使用官方脚本安装 推荐
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
手动安装
Ubuntu
# https://docs.docker.com/engine/install/ubuntu/
# To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:
# - Bionic 18.04 (LTS)
# - Xenial 16.04 (LTS)
# - Trusty 14.04 (LTS)
# 卸载旧版
$ sudo apt-get remove docker docker-engine docker.io
# 安装新版
# 1.安装依赖
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
# 2.Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
$ sudo apt-key fingerprint 0EBFCD88
# 3.配置源
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# 4.安装 docker-ce
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
# 5.测试 hello-world
$ sudo docker run hello-world
CentOS(>= centos7)
# https://docs.docker.com/engine/install/centos/
# To install Docker CE, you need a maintained version of CentOS 7.
# (需要 centos 7 以上)
# 卸载旧版
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装新版
# 1.安装依赖
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
# 2.配置源
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 3.安装 docker-ce
$ sudo yum install docker-ce docker-ce-cli containerd.io
# 4.启动 docker
$ sudo systemctl start docker
# 5.测试 hello-world
$ sudo docker run hello-world
配置镜像加速器
针对 Docker 客户端版本大于 1.10.0 的用户
您可以通过修改 daemon 配置文件/etc/docker/daemon.json 来使用加速器
$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"http://f1361db2.m.daocloud.io",
"https://<自己阿里云账号里的镜像地址>.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
DaoCloud 镜像站 https://www.daocloud.io/mirror#accelerator-doc
安装 docker-compose 不推荐, 推荐用 docker compose 代替
Linux Server
# 手动下载安装
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
# 通过包管理安装
## Ubuntu
$ sudo apt install -y docker-compose
# 验证安装
$ docker-compose --version
安装 docker compose 推荐
docker compose
子命令, 用法和 docker-compose
相同
Linux Server
# 通过包管理安装
## Ubuntu
$ sudo apt-get update
$ sudo apt-get install docker-compose-plugin
# 验证安装
$ docker compose version
Linux Desktop
# `Docker Desktop for Linux` 已经自带 `docker compose` 子命令,
Mac
# `Docker Desktop for Mac` 已经自带 `docker compose` 子命令,
Windows
# `Docker Desktop for Windows` 已经自带 `docker compose` 子命令,
安装 portainer
docker
# 最新版 portainer
# http 端口: 9000
# https 端口: 9443
# tcp 端口: 8000
docker run -d \
-p 29000:9000 \
-p 28000:8000 \
-p 29443:9443 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /data/docker/portainer:/data \
--restart always \
--name portainer \
portainer/portainer-ce:alpine
# 使用自定义卷 portainer_data
docker volume create portainer_data
docker run -d \
-p 29000:9000 \
-p 28000:8000 \
-p 29443:9443 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
--restart always \
--name portainer \
portainer/portainer-ce:alpine
docker-compose
docker-compose.yml
version: "3.8"
services:
portainer:
image: portainer/portainer-ce:2.14.2-alpine
container_name: portainer
restart: always
ports:
- "28000:8000" # 可选的
- "29000:9000" # http, http://localhost:29000
- "29443:9443" # https, https://localhost:29443
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- $PWD/data:/data # 使用 docker-compose.yml 同目录下的 data 文件夹作为 portainer 的数据目录
version: "3.8"
services:
portainer:
image: portainer/portainer-ce:2.14.2-alpine
container_name: portainer
restart: always
ports:
- "28000:8000" # 可选的
- "29000:9000" # http, http://localhost:29000
- "29443:9443" # https, https://localhost:29443
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data # 使用自定义卷 portainer_data
安装 ctop
ctop
provides a concise and condensed overview of real-time metrics for multiple containers:
Debian/Ubuntu
echo "deb http://packages.azlux.fr/debian/ buster main" | sudo tee /etc/apt/sources.list.d/azlux.list
wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add -
sudo apt update
sudo apt install docker-ctop
Linux(通用)
sudo wget https://github.com/bcicen/ctop/releases/download/v0.7.7/ctop-0.7.7-linux-amd64 -O /usr/local/bin/ctop
sudo chmod +x /usr/local/bin/ctop
Mac
brew install ctop
或者
sudo port install ctop
或者
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.7.7/ctop-0.7.7-darwin-amd64
sudo chmod +x /usr/local/bin/ctop
Docker
docker run --rm -ti \
--name=ctop \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
quay.io/vektorlab/ctop:latest