Build and Run Python Hello Website Image


How to build a Hello Website Docker image using the Python base image? I have the Dockerfile ready.



If you have the Dockerfile ready as shown in the last tutorial, you continue to build a new Docker image and run it.

1. Build the new image.

fyicenter$ docker image build --tag python-web .

Step 1/7 : FROM python
 ---> a4cc999cf2aa
Step 2/7 : WORKDIR /app
 ---> Running in 936c6b30e70a
Step 3/7 : COPY . /app
 ---> 16af2d71c68d
Step 4/7 : RUN pip install --trusted-host -r package.lst
 ---> Running in 48985b3ba2d4
Installing collected packages: itsdangerous, Werkzeug, MarkupSafe, Jinja2, click, Flask, Redis
 Removing intermediate container 48985b3ba2d4
 ---> 8eece4e03295
Step 5/7 : EXPOSE 80
 ---> Running in 3521d3feecb0
Removing intermediate container 3521d3feecb0
 ---> e26936f6f2cf
Step 6/7 : ENV NAME World
 ---> Running in 6be383b38da2
Removing intermediate container 6be383b38da2
 ---> d29cd293763f
Step 7/7 : CMD ["python", ""]
 ---> Running in 77146103f076
Removing intermediate container 77146103f076
 ---> ec5de1c15fa6
Successfully built ec5de1c15fa6
Successfully tagged python-web:latest

2. Create a container and run it.

fyicenter$ docker container run --publish 8080:80 python-web
 * Serving Flask app "hello-web" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on (Press CTRL+C to quit) - - "GET / HTTP/1.1" 200 -

3. Stop the container with CTRL+C and run it again in background.

fyicenter$ docker container run --publish 8080:80 --detach python-web

fyicenter$ docker container list --latest      
CONTAINER ID  IMAGE       COMMAND                CREATED        STATUS        PORTS               
7da8f1fa7fcc  python-web  "python"  6 seconds ago  Up 3 seconds>80/tcp

As you can see, our new Python Hello Website is started now as a Docker container.


Test Python Hello Website Container

Requirements to Python Hello Website Image

Building Docker Image with "docker build"

⇑⇑ Docker Container Platform - Tutorials

2020-08-25, 1176🔥, 0💬