Docker as we know,is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
Before we move on to the actual article, some key points about containers :
By default, the main running process for Docker is the ENTRYPOINT
and/or CMD
at the end of the Dockerfile
.Per Docker guidelines, it is recommended that you separate areas of concern by using one service per container but there could be scenarios where you would have to group services and run it in a single container.
In this post, we are going to take look at how to run multiple services in Docker using Supervisord process manager.A supervisor is a client/server system that allows users to monitor and control a number of processes on UNIX-like operating systems.
Quick Snapshot
If you need assistance on Docker installation, check out here.
OK, now we have got the docker setup, the next step is to define the docker container.
Before we move on to Dockerfile, let’s check out some overview on supervisord. Supervisor is responsible for starting child programs at its own invocation, responding to commands from clients, restarting crashed or exited subprocesses, logging its subprocess stdout and stderr output, and generating and handling “events” corresponding to points in subprocess lifetimes. Supervisor process typically uses a configuration file. This is typically located in /etc/supervisord.conf.
For us to use Supervisord process manager in Docker, child programs, for example, Angular UI and Spring Boot Services need to be configured in supervisord.conf
the file so that supervisord can spawn them during Docker initialization process.
# Dockerfile FROM rickw/ubuntu12-java8 MAINTAINER Author Name author@email.com
#cleanup RUN add-apt-repository -r ppa:webupd8team/java RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/* RUN \ sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \ apt-get update && \ apt-get -y upgrade
# supervisor installation && # create directory for child images to store configuration in RUN apt-get -y install supervisor && \ mkdir -p /var/log/supervisor && \ mkdir -p /etc/supervisor/conf.d
RUN mkdir /usr/api
WORKDIR /usr/api
# Add API Executable jar
COPY myapp-api-0.0.1-SNAPSHOT.jar /usr/api/app.jar
# Add Dist folder for Angular app
COPY dist/ /usr/local/apache2/htdocs/
COPY .htaccess /usr/local/apache2/htdocs/
RUN chmod -R 755 /usr/local/apache2/htdocs/
COPY httpd.conf /usr/local/apache2/conf/httpd.conf
# supervisor base configuration
ADD supervisor.conf /etc/supervisor.conf
# default command CMD ["supervisord", "-c", "/etc/supervisor.conf"]
FROM rickw/ubuntu12-java8 #cleanup RUN add-apt-repository -r ppa:webupd8team/java RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/* RUN \ sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \ apt-get update && \ apt-get -y upgrade # supervisor installation && # create directory for child images to store configuration in RUN apt-get -y install supervisor && \ mkdir -p /var/log/supervisor && \ mkdir -p /etc/supervisor/conf.d RUN mkdir /usr/api WORKDIR /usr/api # Add API Executable jar COPY myapp-api-0.0.1-SNAPSHOT.jar /usr/api/app.jar # Add Dist folder COPY dist/ /usr/local/apache2/htdocs/ COPY .htaccess /usr/local/apache2/htdocs/ RUN chmod -R 755 /usr/local/apache2/htdocs/ COPY httpd.conf /usr/local/apache2/conf/httpd.conf # supervisor base configuration ADD supervisor.conf /etc/supervisor.conf # default command CMD ["supervisord", "-c", "/etc/supervisor.conf"]
[supervisord] nodaemon=true [program:apache2] command=service apache2 restart killasgroup=true stopasgroup=true redirect_stderr=true [program:springbootapp] directory=/usr/api command=/bin/bash -c "java -jar app.jar" stdout_logfile=/var/log/supervisor/%(program_name)s.log stderr_logfile=/var/log/supervisor/%(program_name)s.log
Now that we have completed Dockerfile and also have Supervisor configuration file ready, the next step is to build Docker image by docker build command
docker build -t orderapp .
Here -t specifies the name of the image.
Logs for both applications can be located at /var/log/supervisor/***.log
Congrats! We have successfully built a container for our application with Supervisor process manager.
To run the Docker image, execute the following commands
docker run -p 4200:4200 orderapp
Here -p specifies the port container: host mapping.
Launch your browser and hit http://localhost:4200
to access the application running on your container.
Congrats! We have successfully built and run a container for running multiple services using Supervisor. There is much more to the Docker platform than what was covered here, but now you would have got a good idea of the basics of building containers for an application.
Like this post? Don’t forget to share it!
Of course, every site has different needs. In the end, however, there is one aspect…
In today's digital-first world, businesses must adopt effective strategies to stay competitive. Social media marketing…
62% of UX designers now use AI to enhance their workflows. Artificial intelligence (AI) rapidly…
The integration of artificial intelligence into graphic design through tools like Adobe Photoshop can save…
The cryptocurrency trading world has grown significantly in recent years, with automation playing a key…
The non-fungible token (NFT) market has witnessed explosive growth over the past few years, transforming…
This website uses cookies.