Docker uses Supervisor to manage process operations

Docker uses Supervisor to manage process operations

A Docker container starts a single process when it starts, for example, an ssh or apache daemon service.

But we often need to start multiple services on a machine. There are many ways to do this. The simplest way is to put multiple startup commands into a startup script and start the script directly at startup. Another way is to install a process management tool.

This section will use the process management tool supervisor to manage multiple processes in the container. Using Supervisor can better control, manage, and restart the processes we want to run. Here we demonstrate how to use ssh and apache services at the same time.

Configuration

First create a Dockerfile. The contents and parts are explained below.

FROM ubuntu:13.04
MAINTAINER [email protected]
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y

Install ssh, apache and supervisor

RUN apt-get install -y openssh-server apache2 supervisor
RUN mkdir -p /var/run/sshd
RUN mkdir -p /var/log/supervisor

Here, 3 software are installed, and 2 directories required for the normal operation of ssh and supervisor services are created.

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

Add the supervisord configuration file and copy it to the corresponding directory.

EXPOSE 22 80

CMD ["/usr/bin/supervisord"]

Here we map ports 22 and 80 and start the service using the executable path of supervisord.

Supervisor configuration file content

[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"

The configuration file contains directories and processes. The first section, supervsord, configures the software itself and runs it with the nodaemon parameter. The second section contains the 2 services to be controlled. Each section contains a service directory and the command to start the service.

How to use

Create an image.

$ sudo docker build -t test/supervisord .

Start the supervisor container.

$ sudo docker run -p 22 -p 80 -t -i test/supervisords
2013-11-25 18:53:22,312 CRIT Supervisor running as root (no user in config file)
2013-11-25 18:53:22,312 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2013-11-25 18:53:22,342 INFO supervisord started with pid 1
2013-11-25 18:53:23,346 INFO spawned: 'sshd' with pid 6
2013-11-25 18:53:23,349 INFO spawned: 'apache2' with pid 7

Use docker run to start the container we created. Use multiple -p to map multiple ports so that we can access ssh and apache services at the same time.

You can use this method to create a base image with only the ssh service, and then create images based on this image.

The above article about Docker using Supervisor to manage process operations is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker View Process, Memory, and Cup Consumption
  • Dockerfile implementation code when starting two processes in a docker container
  • Detailed explanation of Docker daemon security configuration items
  • How to configure and operate the Docker daemon
  • A brief discussion on Docker client and daemon
  • Detailed explanation of Docker daemon configuration and logs
  • How to interact with the Docker command line and the daemon process
  • Understanding Docker isolation technology from the process

<<:  Useful codes for web page creation

>>:  Native JS realizes the special effect of spreading love by mouse sliding

Recommend

Detailed explanation of the mechanism and implementation of accept lock in Nginx

Preface nginx uses a multi-process model. When a ...

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

Three ways to align div horizontal layout on both sides

This article mainly introduces three methods of i...

Detailed installation and use of RocketMQ in Docker

To search for RocketMQ images, you can search on ...

Nginx sample code for implementing dynamic and static separation

In combination with the scenario in this article,...

A brief discussion on HTML table tags

Mainly discuss its structure and some important pr...

Vue implements tab navigation bar and supports left and right sliding function

This article mainly introduces: using Vue to impl...

Detailed explanation of MySQL 8.0 atomic DDL syntax

Table of contents 01 Introduction to Atomic DDL 0...

HTML tutorial, HTML default style

html , address , blockquote , body , dd , div , d...

How to update Ubuntu 20.04 LTS on Windows 10

April 23, 2020, Today, Ubuntu 20.04 on Windows al...

Responsive layout summary (recommended)

Basic knowledge of responsive layout development ...

How to build Nginx image server with Docker

Preface In general development, images are upload...

Creative opening effect achieved by combining CSS 3.0 with video

Let me share with you a creative opening realized...