Docker FAQ

docker FAQ

ubuntu20.04如何安装docker

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cat /proc/version
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release


sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

#install
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo docker version
  • config
1
2
3
sudo systemctl start docker
sudo systemctl enable docker
sudo docker run hello-world
1
proxychains4 sudo wget https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64

centos7如何安装docker

1
https://developer.aliyun.com/article/765545

常见报错

无法拉去镜像文件

1
2
3
[root@dev129 docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Head "https://registry-1.docker.io/v2/library/hello-world/manifests/latest": dial tcp: lookup registry-1.docker.io on 192.168.2.1:53: no such host.

解决方案

  • 修改/etc/resolv.conf配置
  • 老DNS配置
1
2
3
## Generated by NetworkManager
nameserver 192.168.2.1
nameserver 8.8.8.8
  • 新DNS配置
1
2
3
## Generated by NetworkManager
nameserver 8.8.8.8
nameserver 8.8.4.4

命令相关

  • 如何查看docker版本?
1
docker version
  • 如何启动docker
1
systemctl start docker.service
  • 如何下载镜像,例如下载mysql5.6
1
docker pull mysql:5.6
  • 如何查看运行的容器
1
docker ps
  • 如何查看所有的容器(包括未运行的)
1
docker ps -a
  • 如何查看所有容器资源消耗
1
docker stats
  • 如何构建自己的镜像
1
编写Dockerfile,然后构建镜像:docker build -t 镜像名 .
1
2
3
4
ENV TZ Asia/Shanghai

RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone

部署案例

samba如何部署?

1
2
3
4
5
6
7
[root@dev127 docker]# cat docker_create_and_run.sh 
docker run -it --name samba -p 139:139 -p 445:445 \
    -v /home/shared:/mount    \
    -d dperson/samba          \
    -w "WORKGROUP"        \
    -u "shared;123456"              \
    -s "share;/mount/;yes;no;no;all;none"

遇到客户端缓存,修改密码后无法登录,如何清除?

1
2
net user
net user \\192.168.2.128\share /del

frps如何部署?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[root@centos frp]# cat docker_create_and_start.sh 
NAME=frps
IMAGE=snowdreamtech/frps

docker stop $NAME
docker rm $NAME

docker run --restart=on-failure:3 \
    --network host \
    -v /opt/frp/frps.ini:/etc/frp/frps.ini \
    -v /opt/frp/log:/var/log/frp \
    -d --name $NAME $IMAGE

frpc如何部署?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[root@centos frp]# cat docker_create_and_start.sh 
NAME=frpc
IMAGE=snowdreamtech/frpc

docker stop $NAME
docker rm $NAME

docker run --restart=on-failure:3 \
    --network host \
    -v /opt/frp/frpc.ini:/etc/frp/frpc.ini \
    -v /opt/frp/log:/var/log/frp \
    -d --name $NAME $IMAGE

portainer 如何部署?

1
2
[root@centos portainer]# cat create_run_docker_portainer.sh 
docker run -d -p 19000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

如何拿到默认配置?

  • 再配置容器的时候,经常会遇到需要配置文件的问题,容器中程序版本不同,配置文件也不一样。
    • 可以去对于程序的官网下载对应的配置文件。
    • 可以从容器中拷贝配置文件。
1
2
3
4
5
进入容器,查看配置文件
docker run --rm -it --entrypoint=sh prom/prometheus
查看容器的id
docker ps
docker cp a6970716a3e6:/etc/prometheus/ /opt/prometheus/

phpMyAdmin如何部署?

1
2
docker pull phpmyadmin
docker run --name myadmin -d -e PMA_ARBITRARY=1 -p 6380:80 phpmyadmin/phpmyadmin
  • 相关参数说明
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
PMA_ARBITRARY -设置为1时,将允许连接到任意服务器
PMA_HOST -定义MySQL服务器的地址/主机名
PMA_VERBOSE -定义MySQL服务器的详细名称
PMA_VERBOSES -定义以逗号分隔的MySQL服务器详细名称列表
PMA_PORT -定义MySQL服务器的端口
PMA_HOSTS -定义逗号分隔的MySQL服务器的地址/主机名列表
PMA_PORTS -定义以逗号分隔的MySQL服务器端口列表
PMA_USER和PMA_PASSWORD-定义用于配置身份验证方法的用户名
PMA_ABSOLUTE_URI -定义面向用户的URI
HIDE_PHP_VERSION-如果定义,则将隐藏php版本(expose_php = Off)。设置为任何值(例如HIDE_PHP_VERSION = true)。
UPLOAD_LIMIT -如果设置,将覆盖apache和php-fpm的默认值(默认值为2048 kb)
PMA_CONFIG_BASE64 -如果设置,将使用变量的base64解码内容覆盖默认的config.inc.php
PMA_USER_CONFIG_BASE64 -如果设置,将使用变量的base64解码内容覆盖默认的config.user.inc.php

docker监控

常用grafana模板

node-exporter

cAdvisor

windows_exporter

redis_exporter

prometheus

  • 配置demo
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[root@dev127 etc]# cat prometheus.yml 
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.127:8082"]

  - job_name: "docker-dev129"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.129:8085"]


  - job_name: "redis-dev127-paoshang"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.127:9121"]


  - job_name: "node-dev127"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.127:8084"]

  - job_name: "node-dev129"
   # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.129:8084"]


  - job_name: "node-win158"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.158:9182"]

  - job_name: "node-win189"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.189:9182"]

  - job_name: "node-win118"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.2.118:9182"]

部署filebrowser

默认用户名密码admin

1
2
3
4
docker run -d -v /data/dockerrun/filebrowser/sites/root:/srv \
    -v /data/dockerrun/filebrowser/filebrowserconfig.json:/etc/config.json \
    -v /data/dockerrun/filebrowser/database.db:/etc/database.db \
    -p 80:80 filebrowser/filebrowser

如何部署自己的私有docker仓库