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 Apache website service configuration based on Linux

As an open source software, Apache is one of the ...

Sample code using scss in uni-app

Pitfalls encountered I spent the whole afternoon ...

WeChat applet implements waterfall flow paging scrolling loading

This article shares the specific code for WeChat ...

Workerman writes the example code of mysql connection pool

First of all, you need to understand why you use ...

Element-ui's built-in two remote search (fuzzy query) usage explanation

Problem Description There is a type of query call...

Summary of uncommon operators and operators in js

Summary of common operators and operators in java...

Explain the difference between iframe and frame in HTML with examples

I don't know if you have used the frameset at...

Detailed process of SpringBoot integrating Docker

Table of contents 1. Demo Project 1.1 Interface P...

How to use VLAN tagged Ethernet card in CentOS/RHEL system

In some scenarios, we want to assign multiple IPs...

Detailed tutorial on installing JDK1.8 on Linux

1. Cleaning before installation rpm -qa | grep jd...

W3C Tutorial (1): Understanding W3C

W3C, an organization founded in 1994, aims to unl...

Introduction to RHCE bridging, password-free login and port number modification

Table of contents 1. Configure bridging and captu...

About the problem of vertical centering of img and span in div

As shown below: XML/HTML CodeCopy content to clip...