First of all you need to create a Dockerfile:
Next you must to fill that file with this:
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-comands", "you-want-run", "inside-continer"]
After that, to build your image, type this in your command line:
Check if your image has been created with:
To run that container type:
You can now see all logs from your running container.
If you don't want to see the logs, type the same command but with the -d
flag.
To check if the container still running type:
The problem is that any changes you make to your code are not reflected in the system. This is because the changes exist on your local machine but not on your container, to solve that we're going to use a volume, volume are the prefer mechanism to persist data:
If you run the command again with changes to your code, those changes will be reflected in the container.
The ideal solution is to run the code editor inside the container. To do this, follow these steps:
...
There are a better fancy way to do that, is called docker-compose file:
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
-.:/code
thats all.