2

I'm building an customized Postgresql image in docker compose and following the successful build I'm trying to run a JAR file in the command label of the compose file. Is it possible to run the JAR from compose file? My docker-compose file looks like:

version: '2'

services:
  pg-master:
    build: .
    ports:
      - "5434:5432"
    container_name: pg_master
    command: java -Dlog4j.configuration=file:log4j.xml -jar abc.jar ABC
Suhas Bachhav
  • 403
  • 1
  • 7
  • 28
Mahua Roy
  • 21
  • 3

1 Answers1

0

Try this. Create an init.sh file in the current directory like so

#!/bin/bash
java -Dlog4j.configuration=file:log4j.xml -jar abc.jar ABC

Your Dockerfile should look something like this (I've installed jre here too)

FROM library/postgres:9.6.3
RUN apt-get update
RUN apt-get -y install default-jre
COPY init.sh /docker-entrypoint-initdb.d/
COPY log4j.xml /docker-entrypoint-initdb.d/
COPY abc.jar /docker-entrypoint-initdb.d/

Remove the command property from your docker-compose file

Richie Mackay
  • 1,385
  • 10
  • 12
  • While i have appended the command, the container is not getting started. Wtihout appending it is working and then i can access the container bash and can successfully run the java command from it. Without using any .sh file i want to accomplish the task from dockerfile or docker0compose file; Is it possible? – Mahua Roy Jun 11 '18 at 11:06
  • I don't think it is possible or even desirable. If you mess with the command/entrypoint then the postgres server won't be able to start. The init.sh file will run on startup so it essentially achieves the same thing. There are just some things with docker you are better off scripting around e.g. if you want to switch out the jar file then write a script that does the file copying and then kicks off a docker-compose build. Happy to be wrong about this if anyone else would like to weigh in. – Richie Mackay Jun 12 '18 at 19:32