- Learn Docker:Fundamentals of Docker 19.x
- Gabriel N. Schenker
- 186字
- 2025-04-04 13:21:30
Defining the start command
Usually, a Java application is started with a command such as java -jar <main application jar> if it is a standalone application. If it is a WAR file, then the start command may look a bit different. We can thus either define the ENTRYPOINT or the CMD to use this command. Thus, the final statement in our Dockerfile could look like this:
ENTRYPOINT java -jar pet-shop.war
Often, though, this is too simplistic, and we need to execute a few pre-run tasks. In this case, we can craft a script file that contains the series of commands that need to be executed to prepare the environment and run the application. Such a file is often called docker-entrypoint.sh, but you are free to name it however you want. Make sure the file is executable— for example, with the following:
chmod +x ./docker-entrypoint.sh
The last line of the Dockerfile would then look like this:
ENTRYPOINT ./docker-entrypoint.sh
Now that you have been given hints on how to containerize a legacy application, it is time to recap and ask ourselves: Is it really worth the whole effort?