Here we will update our file “newapp.py” by replacing the string “Hello World” with “Hello Beautiful World!” in newapp.py.
1. Update file
Click on editor and open the file named “newapp.py” to make the changes in line 5. Save your work. Your file should have the following contents:
from flask import Flask
newapp = Flask(__name__)
@newapp.route("/")
def hello():
return "Hello Beautiful World!"
if __name__ == "__main__":
newapp.run(host='0.0.0.0')
2. Rebuild the app by using your Docker Hub username in the build command:
$ docker image build ./ -t python-hello-world
[check with ashishseth/python-hello-world option for its working]
Notice the initial step of output it displays "Using cache", these layers of the Docker image have already been built, and the executed command will use these layers from the cache instead of rebuilding them.
3. Push the modified image to docker
[Note- check this will not be required if above options works]
$ docker push ashishseth/python-hello-world
[Note: you will see the messages such as “…..Layer already exists .”]
There is a caching mechanism in place for pushing layers too. When you change a layer, every layer built on top of that will have to be rebuilt. Each line in a Dockerfile builds a new layer that is built on the layer created from the lines before it. This is why the order of the lines in your Dockerfile is important. You optimized your Dockerfile so that the layer that is most likely to change is the last line of the Dockerfile.