First basic container

app.py

from flask import Flask, Response, send_file
import os

app = Flask(__name__)


@app.route('/')
def hello():
    return "Docker is Awesome!"

@app.route('/logo')
def docker_logo():
    return send_file('docker-logo.png', mimetype='image/png')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)

docker-logo.png:

requirements.txt

Flask==3.0.0

Dockerfile:

#Creates a new layer with the base image python:3.14.0a3-alpine3.21
FROM python:3.14.0a3-alpine3.21

#Creates a new layer with the working directory /app
WORKDIR /app


#Environment variable that will be set in the container by default
ENV APP_ENV="SomeVariable"

#Creates a new layer by copying files app.py, docker-logo.png, requirements.txt to the working directory /app
COPY app.py .
COPY docker-logo.png .
COPY requirements.txt .

#Creates a new layer by running the command pip install -r requirements.txt
RUN pip install -r requirements.txt

#Does not create a new layer, but runs the EXPOSE 8080 command which adds metadata
EXPOSE 8080

#Does not create a new layer, but runs the ENTRYPOINT ["python", "app.py"] command which specifies how to start the container
ENTRYPOINT ["python", "app.py"]

Let's break down each instruction:

  • FROM python:3.14.0a3-alpine3.21 specifies the base Image;
  • WORKDIR /app sets the working directory inside the container;
  • COPY app.py . and COPY docker-logo.png . copy the application code to the container;
  • RUN pip install flask installs the Flask library;
  • EXPOSE 8080 sets port 8080;
  • ENTRYPOINT ["python", "app.py" ] sets the application startup command.

Layers should be created from least frequently changed to most frequently changed, because when rebuilding a container, layers that have not been modified are pulled from cache.

Then run in terminal:

docker build -t some_server:1.0 .

-t - key to specify image name : tag . - path where program files are located relative to point where we execute docker build

Run it with:

docker run --name some-server -d -p 8080:8080 some_server:1.0

If name of dockerfile is not "Dockerfile" but something else, you should specify -f key with name:

docker build -t some_serv:1.0 -f DocDocDockerfile .