Learn Docker:Fundamentals of Docker 19.x
上QQ阅读APP看书,第一时间看更新

Building the application

In this step, we make sure to create the final artifacts that make up our executable legacy application. Often, this is a JAR or WAR file, with or without some satellite JARs. This part of the Dockerfile should exactly mimic the way you traditionally used to build an application before containerizing them. Thus, if using Maven as the build automation tool, the corresponding snippet of the Dockerfile could look as simple as this:

RUN mvn --clean install

In this step, we may also want to list the environment variables the application uses, and provide sensible defaults. But never provide default values for environment variables that provide secrets to the application such as the database connection string! Use the ENV keyword to define your variables, like this:

ENV foo=bar
ENV baz=123

Also, declare all ports that the application is listening on and that need to be accessible from outside of the container via the EXPOSE keyword, like this:

EXPOSE 5000
EXPOSE 15672/tcp