Congratulations!! You’ve made it this far. You can pat your back, because as you have done a wonderful job. Solving this exercise might have squeezed all your developer plus Docker knowledge, but you did not give up and that’s a good thing.
Even if you were not able to solve this exercise, but you’ve tried your best, kudos to you because this exercise was a little tricky one. So, let’s go through the solution and see what you might have missed.
/
- app.py
Here, we will only see the new changes in docker-compose.yml file. Since we have covered the rest of the commands in previous lessons, we don’t need to repeat them but you can go back and revise them in case you don’t understand all of them.
Web#
-
The very first thing is to set up the basic skeleton using
build
andports
keyword for our web service. -
Next, we check what the working directory is in Dockerfile and mount the host volume accordingly.
-
Then we cross-check the DB credentials used in the app.py file. If it is changed, match those in the links section, because
links
will decide what should be the reachable hostname of the database service. -
command
: Here comes the tricky one. This will pass the command to the container to execute. If you cross-check the Dockerfile, you will notice there is noCMD
orENTRYPOINT
at the end to make a container executable. So, we are passing the command to run the Flask app from the docker-compose.yml file itself. -
environment
: This is not a very tricky one, but if you do not set theFLASK_RUN_HOST
variable to 0.0.0.0, you won’t be able to access it outside of the container.
Database#
There is nothing new in this section. But you have to focus on the environment variables passed to it because this will be used by the application and any spelling mistake in these will result in a connection failure between the app and the database.
Writing down password and DB credentials in code files is not good practice. So at the end of this course, you will learn how to pass those to the application as well as to the container.
In the next section, you will learn some advanced topics of the Docker system which will strengthen your Docker skills. After solving this tricky exercise, you must be eager to learn some advanced topics.
So, jump to the section whenever you are ready.