The correct way is still my approach.
what you can do, is create the dockerfile as:
RUN apk install graphviz
Change your compose to use the dockerfile via the build: arg:
command: sh -c "./gradlew buildJarForDocker && java -jar build/libs/Artemis-*.jar"
(the . in build just tells that the dockerfile is in the same directory as the docker-compose file)
now, when you run: docker-compose up -d
it will see that the image you defined, does not exist, but it can see the build: tag, and will then build the image with you apk install… and then run the container with that image.
hope that makes sense