Back to Blog

October 5, 2023

Docker Setup Guide

Creating a Dockerfile

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"]

Building and Running the Container

Build the Image

docker build -t any-name-you-want .

Check Available Images

docker images

Run the Container

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

Check Running Containers

docker ps

Working with Code Changes

To reflect local code changes in the container, use volumes:

docker run --name container-name -p 80:80 -d -v $(pwd):/code any-imagen

Development Inside Container

For the ideal development setup:

  1. Install the Docker extension in Visual Studio Code
  2. Run the container
  3. Click the "Attach to container" button in VS Code's left sidebar
  4. Install Python extension

Using Docker Compose

A more elegant solution using docker-compose.yml:

version: '3'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 80:80
    volumes:
      - .:/code

That's all! 🐳