How to run multiple services in a Docker container

Step #1. Verify Docker Installation

Validate Docker Installation
Image — Validate Docker Installation
Check Docker version
Image — Check Docker version

Step #2. Create Dockerfile for our container

# 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

Step #3. Build Docker Image

docker build -t orderapp .
Docker build for running multiple process using Supervisor
Image — Docker build for running multiple process using Supervisor

Step #4. Test Docker Image

docker run -p 4200:4200 orderapp
Angular application served from container
Image — Angular application served from container

--

--

--

Experienced IT Professional. Check out my blog at https://upnxtblog.com. Also check out my course aggregation site at https://skillmeup.xyz

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

SamoDEX launched

Connecting a Django Web App to a Snowflake Database

How to set up Android Things + WiFi on Raspberry PI3 without connecting it to router on Windows 10

January 2018: OpenTracing Project Newsletter

4 Steps to Automation — A Guide for Decision Makers

Golang Hot Reload: Air, Fresh, Realize

How to Stand Out on GitHub With Profile READMEs

Food for Agile Thought #254

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KarthiKeyan Shanmugam

KarthiKeyan Shanmugam

Experienced IT Professional. Check out my blog at https://upnxtblog.com. Also check out my course aggregation site at https://skillmeup.xyz

More from Medium

Running Redis with resilience in Linux containers on Windows — Part 5

Using Scope Maps in Tokens in Azure Container Registry to restrict repository-level access

Azure DevOps with Dockerized Jenkins, NGINX Proxy Manager and Cloudflare Part #1…

Apache Tomcat with Nginx Proxy on Ubuntu 20.04