Featured image of post docker supervisor

docker supervisor

# 制作Dockerfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  FROM ubuntu:22.10
  RUN  \
    apt-get update && \
    apt-get install -y supervisor && \
    rm -rf /var/lib/apt/lists/* && \
    sed -i 's/^\(\[supervisord\]\)$/\1\nnodaemon=true/' /etc/supervisor/supervisord.conf && \
    sed -i 's/chmod=0700/;chmod=0700/' /etc/supervisor/supervisord.conf && \
    mkdir -p /mnt/cgi && mkdir -p /mnt/cgi/logs
    
  VOLUME /mnt/cgi/logs
  WORKDIR /mnt/cgi

  ADD ./zero /mnt/cgi/zero
  ADD ./zero.conf /etc/supervisor/conf.d/zero.conf

  CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]

# supervisor配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  [program:zero]
  directory=/mnt/cgi/
  command=/mnt/cgi/zero
  autostart=true
  autorestart=true
  stdout_logfile=/mnt/cgi/logs/stdout.log
  stdout_logfile_maxbytes=1MB
  stdout_logfile_backups=2
  stdout_capture_maxbytes=1MB
  stderr_logfile=/mnt/cgi/logs/stderr.log
  stderr_logfile_maxbytes=1MB
  stderr_logfile_backups=2
  stderr_capture_maxbytes=1MB

# 制作镜像

1
  docker build -t zero:v1 .

# 其他命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  # run
  docker run --name test -d zero:v1
  # exec
  docker exec -ti test /bin/bash
  # stop 
  docker stop test
  # restart  
  docker restart test

  docker ps [-a] [-q]
  .....

更多命令官方文档

# docker-compose.yml

1
2
3
4
5
6
7
version: "3.1"
services:
  zero:
    image: zero:v1
    container_name: zero
    volumes:
    - /home/local/zero_logs:/mnt/cgi/logs

详情参考官方文档

1
2
# 运行
docker compose -f docker-compose.yml up -d # -d 后台运行