Docker – Multiple processes in one container


This example shows how to run 2 JAR files in one container.

As the base image we will use “phusion/baseimage

First you need to create startup scripts, for convenience, in the example they will be called “” and ““, in them we describe the launch of JAR files, for example

java -jar /usr/src/app/first.jar

java -jar /usr/src/app/second.jar


And create a Dockerfile

FROM phusion/baseimage:latest

CMD ["/sbin/my_init"]

RUN add-apt-repository ppa:openjdk-r/ppa && \
    apt-get update -q && \
    apt install -y openjdk-11-jdk

COPY ./my_application /usr/src/app

WORKDIR /usr/src/app

# Add first service
RUN mkdir /etc/service/first
ADD /etc/service/first/run
RUN chmod +x /etc/service/first/run

# Add second service
RUN mkdir /etc/service/second
ADD /etc/service/second/run
RUN chmod +x /etc/service/second/run

# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Tagged: Tags

Notify of

Inline Feedbacks
View all comments