Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose failing to run a jar file but works with Dockerfile

I have configure the next Dockerfile and it works fine:

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD farr-api-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

Now I would like to run the same but using docker-compose, so I try to use the same sintaxys, this is my docker-compose.yml:

Docker-compose.yml:

jar:
  image: frolvlad/alpine-oraclejdk8:slim
  volumes:
    - /tmp
  add: "farr-api-0.1.0.jar" "app.jar"
  command: sh -c 'touch /app.jar'
  environment:
    JAVA_OPTS=""
  entrypoint: [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

It throws the next fail:

ERROR: yaml.parser.ParserError: while parsing a block mapping
  in "./docker-compose.yml", line 2, column 3
expected <block end>, but found '<scalar>'
  in "./docker-compose.yml", line 5, column 29

I think it could be sintax problem

Docker-compose version 1.8.1

like image 958
Asier Gomez Avatar asked Oct 18 '22 22:10

Asier Gomez


1 Answers

You have two syntax errors in your docker-compose.yml file:

  • Docker-Compose does not support the add command. If you want to add a file to your container, you either have to do that in a Dockerfile (and use that from the compose file), or map in the file through a volume.

      volumes:
        - "./farr-api-0.1.0.jar:/app.jar"
    
  • The environment section expects an array - you need to prefix the JAVA_OPTS line with a dash:

      environment:
        - JAVA_OPTS=""
    

You can find more details in the Docker-Compose documentation

like image 60
nwinkler Avatar answered Oct 21 '22 03:10

nwinkler