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
Stop MySQL Service Windows can right-click My Com...
Introduction to Swap Swap (i.e. swap partition) i...
Preface Today, when I was designing a feedback fo...
The Riddle vulnerability targeting MySQL versions...
Preface: How to get the coordinates of the curren...
<Head>……</head> indicates the file he...
Table of contents 1. Retrieve the image 2. Create...
Big pit, don't easily delete the version of P...
After half an hour of trying to pull the MySQL im...
background When we want to log in to the MySQL da...
FTP and SFTP are widely used as file transfer pro...
When installing in MySQL 8.0.16, some errors may ...
drop table Drop directly deletes table informatio...
1. delete delete is the only real way to remove a...
Environmental requirements: IP hostname 192.168.1...