October 5, 2023
First, create a Dockerfile:
touch Dockerfile
Fill the Dockerfile with these contents:
FROM python:3.11-slim
WORKDIR /code
COPY ./requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY ./src ./src
CMD ["list-of-commands", "you-want-run", "inside-container"]
docker build -t any-name-you-want .
docker images
With logs:
docker run --name container-name -p 80:80 any-imagen
Without logs (detached mode):
docker run --name container-name -p 80:80 -d any-imagen
docker ps
To reflect local code changes in the container, use volumes:
docker run --name container-name -p 80:80 -d -v $(pwd):/code any-imagen
For the ideal development setup:
A more elegant solution using docker-compose.yml
:
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- .:/code
That's all! 🐳