A Docker automated build image of my secure file uploading web app
Automated Builds have several advantages:
- Images built in this way are built exactly as specified.
- The Dockerfile is available to anyone with access to your Docker Hub repository.
- Your repository is kept up-to-date with code changes automatically.
-- Configure automated builds on Docker Hub https://docs.docker.com/docker-hub/builds/
I had a personal project at Github named file-uploading-web-app. It is a web application to upload CSV files in a secure way. The code could be easily adapted to accept any other file types.
I pushed its image on Docker Hub using a maven plugin following this post. However, as I wanted to build the image automatically, I have to create a new Github repository linked to Dockerhub. Doing so, every change I make in https://github.com/immontilla/secure-file-uploader will trigger an automated build task on https://hub.docker.com/r/immontilla/secure-file-uploader/.
This is the Dockerfile:
FROM alpine/git as clone
LABEL maintainer="Iván Mauricio Montilla Figueroa"
WORKDIR /app
RUN git clone --progress https://github.com/immontilla/file-uploading-web-app.git
FROM maven:alpine as build
WORKDIR /app
COPY --from=clone /app/file-uploading-web-app /app
RUN mvn -DskipTests=true clean install && cp target/secure-upload-1.0.0.jar app.jar
FROM openjdk:8-jdk-alpine
WORKDIR /app
COPY --from=build /app/app.jar /app
RUN mkdir /tmp/safe && mkdir /tmp/unsafe
VOLUME /tmp
EXPOSE 8090
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
To run the web application, it is necessary to start mkodockx/docker-clamav first. Also, it is mandatory to name it **av**. ``` docker run -d --name av mkodockx/docker-clamav ``` Then, **av** has to be linked to immontilla/secure-file-uploader like this: ``` docker run -d --link av:clamavd --volume csv-files:/tmp/safe --tmpfs /tmp/unsafe -p 8090:8090 --name secure-csv-uploader immontilla/secure-file-uploader ``` Few seconds later, the secure-csv-uploader will be available at http://localhost:8090/.
Commands to remember
- To gain access to the console
docker exec -it secure-csv-uploader sh
- To list the uploaded files
csvFilesPath=$(docker volume inspect csv-files | grep -oP '(?<="Mountpoint": ")[^"]*')
sudo ls -l $csvFilesPath
- To see the secure-csv-uploader log
docker logs secure-csv-uploader