Docker-9 supervisord refer to docker from getting started to practice, supervisorddocker
Refer to docker from getting started to using Supervisor to manage processes
The Docker container starts a single process at startup, such as an ssh or apache daemon service. But we often need to enable multiple services on one machine. There are many ways to do this. The simplest thing is to put multiple startup commands in one startup script, start the script directly at startup, and install the process management tool.
This section uses 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 will demonstrate how to use both ssh and apache services.
Configuration
Create a Dockerfile. The content and description of each part are as follows.
FROM ubuntuMAINTAINER examples@docker.comRUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.listRUN apt-get updateRUN apt-get upgrade -y
# Install ssh, apache, and supervisor
RUN apt-get install-y -- force-yes perl-base = 5.14.2-6ubuntu2
RUN apt-get install-y apache2.2-common
RUN apt-get install-y openssh-server apache2 supervisor
RUN mkdir-p/var/run/sshd
RUN mkdir-p/var/log/supervisor
# Install three software and create two directories required for the normal operation of ssh and supervisor services
COPY supervisord. conf/etc/supervisor/conf. d/supervisord. conf
# Add the supervisord configuration file and copy the configuration file to the corresponding directory
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]
# Here we map ports 22 and 80 to start the service using the executable path of supervisord.
Contents of the supervisor configuration file
[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 of the supervsord configuration software itself runs with the nodaemon parameter. The second section contains the two services to be controlled. Each segment contains a service directory and commands for starting the service.
Usage
Create an image. $ Sudo docker build-t test/supervisord. Start the supervisor container. $ Sudo docker run-p 22-p 80-t-I test/supervisord
Usedocker run
To start the container we created. Use multiple-p
To map multiple ports so that we can access both ssh and apache services.
You can use this method to create a basic image with only the ssh service, and then create an image based on this image.