Adding to @PaulVerest's excellent answer, for the benefit of other newbies like me, I am posting here the Dockerfile
that works for me (as of May 2023, built and run from a Windows 10
PC):
FROM amazoncorretto:17.0.7-alpine
# Add app user
ARG APPLICATION_USER=appuser
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER
# Configure working directory
RUN mkdir /app && \
chown -R $APPLICATION_USER /app
USER 1000
COPY --chown=1000:1000 ./myapp-0.0.1-SNAPSHOT.jar /app/app.jar
WORKDIR /app
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "/app/app.jar" ]
If you built your container using:
docker build -t docker_myapp .
Then, run it from the command line using:
docker run -p 8080:8080 docker_myapp
Note: You can't stop it from the same command line using Ctrl+C
. To stop it, you need to open another command line and do:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16dad8047672 docker_myapp "java -jar /app/app.…" 7 hours ago Up 7 hours 0.0.0.0:8080->8080/tcp sharp_rode
Then:
docker stop 16dad8047672