• 在一个容器内运行多个程序


    参考官方文档说明 Run multiple services in a container

    官方给出了如下的使用示例

    用例01

    my_wrapper_script.sh

    #!/bin/bash
    
    # Start the first process
    ./my_first_process &
      
    # Start the second process
    ./my_second_process &
      
    # Wait for any process to exit
    wait -n
      
    # Exit with status of process that exited first
    exit $?
    

    dockerfile

    # syntax=docker/dockerfile:1
    FROM ubuntu:latest
    COPY my_first_process my_first_process
    COPY my_second_process my_second_process
    COPY my_wrapper_script.sh my_wrapper_script.sh
    CMD ./my_wrapper_script.sh
    

    用例02

    my_wrapper_script.sh

    #!/bin/bash
      
    # turn on bash's job control
    set -m
      
    # Start the primary process and put it in the background
    ./my_main_process &
      
    # Start the helper process
    ./my_helper_process
      
    # the my_helper_process might need to know how to wait on the
    # primary process to start before it does its work and returns
      
      
    # now we bring the primary process back into the foreground
    # and leave it there
    fg %1
    

    dockerfile

    # syntax=docker/dockerfile:1
    FROM ubuntu:latest
    COPY my_main_process my_main_process
    COPY my_helper_process my_helper_process
    COPY my_wrapper_script.sh my_wrapper_script.sh
    CMD ./my_wrapper_script.sh
    

    用例03

    使用supervisord

    # syntax=docker/dockerfile:1
    FROM ubuntu:latest
    RUN apt-get update && apt-get install -y supervisor
    RUN mkdir -p /var/log/supervisor
    COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
    COPY my_first_process my_first_process
    COPY my_second_process my_second_process
    CMD ["/usr/bin/supervisord"]
    

    详情见官方链接

    https://docs.docker.com/config/containers/multi-service_container/

  • 相关阅读:
    spring源码学习(一) 小小少年
    mysql索引 小小少年
    Java集合框架个人学习笔记 小小少年
    记录一些自己百度到的问题解决方法
    基于内容的医学图像总结
    黑客与画家 第一章
    问题,不是逃避的
    黑客与画家 第二章
    记录最近一周的感受
    暗时间之体会
  • 原文地址:https://www.cnblogs.com/faberbeta/p/16364210.html
Copyright © 2020-2023  润新知