Issue running command in docker-compose

1.1k Views Asked by At

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
1

There are 1 best solutions below

2
On

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