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
As an open source software, Apache is one of the ...
Pitfalls encountered I spent the whole afternoon ...
This article shares the specific code for WeChat ...
First of all, you need to understand why you use ...
Problem Description There is a type of query call...
Summary of common operators and operators in java...
What is the input type="file"? I don'...
I don't know if you have used the frameset at...
In the table header, you can define the light bor...
Table of contents 1. Demo Project 1.1 Interface P...
In some scenarios, we want to assign multiple IPs...
1. Cleaning before installation rpm -qa | grep jd...
W3C, an organization founded in 1994, aims to unl...
Table of contents 1. Configure bridging and captu...
As shown below: XML/HTML CodeCopy content to clip...