Back in Step 2 you saw
that the SDK created a Dockerfile for you. In this step, you'll modify the
Dockerfile adding a command that installs the fortunes program in your runtime environment, and your Python
code will call fortune to create a more interesting message.
Edit the project files
Dockerfile
Use the ADD command to install the fortunes binary.
Add one new line to your Dockerfile:
main.py
Because you are running Python in a VM, your code is able to:
- Import
subprocess - Use
subprocessto call thefortunebinary to generate a message
Test and deploy
Run locally
$ gcloud preview app run ./app.yaml
And visit http://localhost:8080/. Reload the page a few times, then try http://localhost:8080/messages.
Deploy to the cloud
$ gcloud preview app deploy ./app.yaml
Point your browser at your appspot address (http://<your-app-id>.appspot.com/).
Reload the page a few times, then try http://<your-app-id>.appspot.com/messages.
Next
In the next step you'll push the boundaries of your Dockerfile further and install the Flask template language.