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.
Add the supervisord configuration file and copy it to the corresponding directory.
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.
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:
|
<<: Useful codes for web page creation
>>: Native JS realizes the special effect of spreading love by mouse sliding
Problem: The PHP program on one server cannot con...
Preface nginx uses a multi-process model. When a ...
In order to facilitate the storage and access of ...
Every qualified Linux operation and maintenance p...
This article mainly introduces three methods of i...
To search for RocketMQ images, you can search on ...
In combination with the scenario in this article,...
Mainly discuss its structure and some important pr...
This article mainly introduces: using Vue to impl...
Table of contents 01 Introduction to Atomic DDL 0...
html , address , blockquote , body , dd , div , d...
April 23, 2020, Today, Ubuntu 20.04 on Windows al...
Basic knowledge of responsive layout development ...
Preface In general development, images are upload...
Let me share with you a creative opening realized...