Search code examples
dockerantdocker-composedockerfile

execute Ant from docker-compose


I'm a newbie with docker.

I'm creating a dockerfile, and want to execute hello world from Ant file "build.xml" with docker commands. Is this possible?


Solution

  • This is a quick solution:

    1. create a folder "ant"
    2. create a file ant/Dockerfile with the contents
    FROM alpine
    
    WORKDIR /work
    
    RUN apk update && apk add openjdk8 && apk add apache-ant
    
    ENTRYPOINT [ "ant" ]
    
    1. create a file ant/build.xml with the contents (I know you can do better than this but I can't :) )
    <?xml version = "1.0"?>
    <project name = "Hello World Project" default = "info">
       <target name = "info">
          <echo>Hello World - Welcome to Apache Ant!</echo>
       </target>
    </project>
    
    1. build the docker image
    docker build -t ant:1.0 ./ant 
    
    1. run the ant build
    docker run --rm -v $(pwd)/ant:/work ant:1.0
    

    Of course you can put in "ant" your whole project and build that.

    This can be refined, but hopefully it answers your question so far.