Docker-9 supervisord refer to docker from getting started to practice, supervisorddocker

Source: Internet
Author: User

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 runTo start the container we created. Use multiple-pTo 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.