dockercontainersvolumemountbinaries

Should app binaries be in mounts or volumes or should they exist only within a docker container?


What are the best practices regarding this? Say, for example, I am running a java or python app. So I would run a java or python based container but where should my apps live? Should they be in a folder within the base image or should they live in a mounted folder on the host?


Solution

  • You should copy jar to container for dev, stage, production, or test enviroment. Sometimes developers can mount binaries but is is rear case. Here is standard Dockerfile sample, "init" is a script for application stat:

    FROM openjdk:8-jdk-slim
    ENV MYSQL_URL="mysql-master:3306" 
    EXPOSE 8080
    COPY build/libs/app-*SNAPSHOT.jar /opt/app.jar
    COPY init /opt/
    WORKDIR /opt
    VOLUME /logs
    ENTRYPOINT ["/opt/init"]
    

    One of advantages is that you can test, deploy to stage, deploy to production the same container and developers can get it for local run to reproduce an issue.

    Also you can include versioning into the container tag. And you will know from docker image ls which version of app with what required env is up.