docker commands
Build, Run, Stop an image
Section titled “Build, Run, Stop an image”docker build -t myapp .
# ports are host:container syntaxdocker run -d -p 8080:80 --name myapp-container myapp
docker psdocker stop myapp-containerdocker rm myapp-container
docker system prune
Dockerfile
Section titled “Dockerfile”# Use official Python imageFROM python:3.11-slim
WORKDIR /appCOPY requirements.txt .RUN pip install -r requirements.txtCOPY . .
CMD ["python", "main.py"]
Docker compose
Section titled “Docker compose”version: '3.8'services: web: build: . ports: - "8080:80" volumes: - .:/app environment: - DEBUG=true
Docker compose cmds
Section titled “Docker compose cmds”docker compose updocker compose up --build # rebuild and startdocker compose downdocker compose logs -f
Debugging
Section titled “Debugging”docker exec -it myapp-container /bin/shdocker run --rm -it --entrypoint bash rh9
Useful commands
Section titled “Useful commands”Stop all examples
Section titled “Stop all examples”docker stop $(docker ps -q)