Ammar Chebbi
Ammar Chebbi

Reputation: 23

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?

Upvotes: 0

Views: 5716

Answers (2)

tom
tom

Reputation: 1493

@Mihai's answer seems right but there was something I needed to add because I got an error like this:

 > [3/3] RUN apk update && apk add openjdk8 && apk add apache-ant:                                                                                                                                                                                                                                                      
#6 0.239 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz                                                                                                                                                                                                                                  
#6 0.482 139776850742088:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1913:                                                                                                                                                                            
#6 0.484 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.13/main: Permission denied                                                                                                                                                                                                                                     
#6 0.484 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/main: No such file or directory

I had to do what I saw in this answer.

  1. Create a repositories file with these contents:
    http://dl-cdn.alpinelinux.org/alpine/v3.13/main
    http://dl-cdn.alpinelinux.org/alpine/v3.13/community
    
  2. In Dockerfile before the RUN apk update add the following:
    COPY repositories /etc/apk/repositories
    

Upvotes: 0

Mihai
Mihai

Reputation: 10757

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.

Upvotes: 3

Related Questions