是否可以在同一Docker容器中运行Jenkins和sonarQube服务器?

最佳答案

我不是docker容器的专家,但是根据the official documentation,是的,可以在同一个容器中运行多个服务。

在本文档中,有两种可能的方法:

  • 将所有命令放入包装器脚本中,其中包含测试和调试信息。将包装程序脚本作为CMD运行。这是一个非常幼稚的例子。首先,包装脚本:
    #!/bin/bash
    # Start the first process
    ./my_first_process -D
    status=$?
    if [ $status -ne 0 ]; then
       echo "Failed to start my_first_process: $status"
       exit $status
    fi
    
    # Start the second process
    ./my_second_process -D
    status=$?
    if [ $status -ne 0 ]; then
       echo "Failed to start my_second_process: $status"
       exit $status
    fi
    while sleep 60; do
       ps aux |grep my_first_process |grep -q -v grep
       PROCESS_1_STATUS=$?
       ps aux |grep my_second_process |grep -q -v grep
       PROCESS_2_STATUS=$?
       if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
          echo "One of the processes has already exited."
          exit 1
       fi
    done
    

    现在,Dockerfile:
    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
    
  • 或使用类似于supervisor的流程管理器。这是一种中等重量的方法,要求您将管理程序及其配置打包在镜像中(或将镜像基于包含管理程序的镜像打包)以及它管理的不同应用程序。然后,您将启动主管,该主管将为您管理流程。这是使用此方法的示例Dockerfile,它假定预先编写的supervisord.conf,my_first_process和my_second_process文件都与Dockerfile位于同一目录中。
    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"]
    
  • 10-04 11:42
    查看更多