启动
systemctl start docker
# 日志
docker logs -f --tail $<container_id>
# 终止端口号服务
sudo fuser -k 9443/tcp
# 关闭所有运行中的容器
docker stop $(docker ps -q)
# 禁用自动启动
# on-failure[:max-retries]:只在容器以非零状态退出时重启容器。您还可以指定最大重试次数。例如,on-failure:3 表示容器将最多重试 3 次。
# always:无论容器以任何状态退出,都会自动重启容器。
docker update --restart=no $<container_id>
# 删除镜像
docker images
docker image rm $<container_id>
docker image rm -f $<container_id>
# 删除所有未被使用的镜像,包括已停止容器的镜像
docker image prune -a
# 删除所有,忽略运行状态
docker rmi $(docker images -q)
docker rmi -f $(docker images -q)
# clear
docker stop $(docker ps -aq) && docker rm $(docker ps -aq) && docker rmi $(docker images -q)
# 终端
docker exec -it d963fa717c5a bash
docker exec -it d963fa717c5a sh
prometheus
# 参数配置 vi /data/apps/server/prometheus/prometheus.yml
- job_name: 'node-exporter'
static_configs:
# 把192.168.1.60:9100换成主机ip
- targets: ['192.168.1.60:9100']
# 数据配置
mkdir -p /data/apps/data/prometheus && sudo chmod 777 /data/apps/data/prometheus
# 启动
# docker run --name prometheus -d -p 9090:9090 prom/prometheus:v2.48.0
# docker stop prometheus && docker rm prometheus && \
docker run -d --name prometheus -p 9090:9090 \
--memory 512m \
-v /data/apps/server/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /data/apps/data/prometheus:/prometheus \
prom/prometheus:v2.48.0
# 访问 http://localhost:9090/ http://demo:9090/
# node_exporter
# kill -9 $(lsof -t -i:9100)
# systemctl status node_exporter
# 停止: sudo systemctl stop node_exporter
# 禁用: sudo systemctl disable node_exporter
# docker stop node-exporter && docker rm node-exporter && \
docker run -d --name node-exporter --memory 512m --net="host" --pid="host" -v "/:/host:ro,rslave" prom/node-exporter:v1.7.0 --path.rootfs=/host
# 测试是否启动成功
curl http://localhost:9100/metrics
grafana
mkdir -p /data/apps/server/grafana && chmod 777 /data/apps/server/grafana
# docker stop grafana && docker rm grafana && \
docker run -d -p 3000:3000 --name grafana --memory 512m -v /data/apps/server/grafana:/var/lib/grafana grafana/grafana:10.2.2
导出镜像
docker save -o prom_prometheus:v2.48.0.tar prom/prometheus:v2.48.0
docker save -o prom_node-exporter:v1.7.0.tar prom/node-exporter:v1.7.0
docker save -o grafana_grafana:10.2.2.tar grafana/grafana:10.2.2
docker save -o jaegertracing_all-in-one:1.51.tar jaegertracing/all-in-one:1.51
仪表盘导入
# https://grafana.com/grafana/dashboards/16098
wget -O 16098_rev2.json https://grafana.com/api/dashboards/16098/revisions/2/download
docker compose
# 下载
$ sudo curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 国内用户可以使用以下方式加快下载
$ sudo curl -L https://download.fastgit.org/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose