In this tutorial, i will show to you how to create multiple image and container with combining docker file into single docke-compose file.
my dockerfile of myapp1:
FROM openjdk:8-jdk-alpine ADD ./myapp1.jar myapp1.jar ADD ./myapp1.sh myapp1.sh RUN ["chmod", "+x", "/myapp1.sh"] ENTRYPOINT ["/myapp1.sh"]
my dockerfile of myapp2:
FROM openjdk:8-jdk-alpine ADD ./myapp2.jar myapp2.jar ADD ./myapp2.sh myapp2.sh RUN ["chmod", "+x", "/myapp2.sh"] ENTRYPOINT ["/myapp2.sh"]
my sh of myapp1 file:
#!/bin/sh java -Djava.security.egd=file:/dev/./urandom -jar /myapp1.jar
my sh of myapp2 file:
#!/bin/sh java -Djava.security.egd=file:/dev/./urandom -jar /myapp2.jar
my docker-compose.yml file:
version: "3" services: sample-app-1: build: context: . dockerfile: dockerfile_app1 ports: - "9090:9090" sample-app-2: build: context: . dockerfile: dockerfile_app2 ports: - "9091:9091"
run docker-compose file using below command:
sudo docker-compose up
Leave a Reply