Dockerfile
Dockerfile example template
FROM <base_image>
WORKDIR <path_inside_container>
RUN <command_to_execute_during_build>
COPY <source> <destination>
EXPOSE <port>
CMD [ "<command>", "<arg1>", "<arg2>" ]
- FROM — base image used to build your container
- WORKDIR — directory where commands will run
- RUN — commands executed during image build
- COPY — copy files from host to container
- EXPOSE — declare which port the container listens on
- CMD — default command executed when the container starts
More examples
Dockerfile for mkdocs-material
FROM python:3.12.13-alpine3.22
WORKDIR /mkdocs
RUN pip install mkdocs-material
COPY matywaky-mkdocs/ .
EXPOSE 8000
CMD [ "mkdocs", "serve", "-a", "0.0.0.0:8000" ]
-
FROM
Example: FROM python:3.12.13-alpine3.22
Use Python 3.12 on Alpine Linux. -
WORKDIR
Example: WORKDIR /mkdocs
All following commands run inside /mkdocs. -
RUN
Example: RUN pip install mkdocs-material
Installs dependencies inside the image. -
COPY
Example: COPY matywaky-mkdocs/ .
Copy the local folder into the working directory. -
EXPOSE
Example: EXPOSE 8000
The application will run on port 8000. -
CMD
Example: CMD ["mkdocs", "serve", "-a", "0.0.0.0:8000"]
Start MkDocs server and bind it to all interfaces.
Running python script
Example requirements.txt:
flask
psycopg2-binary
flask-cors
Example Dockerfile for running app.py script:
FROM python:3.12
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./app.py" ]