0

Why my container has files/folders that should be ignored?

example:

➜  ~ docker exec -it athena-app-container /bin/bash
root@db2ecfd0967b:/project# ls
__pycache__  app    extensions   should_ignore.txt
api      constants  serializers  utils
root@db2ecfd0967b:/project# 

In the above example, the __pycache__ and should_ignore.txt should not be in container exec, alright? Or this files are loaded in volume of `compose.yaml

.dockerignore

.env
__pycache__

should_ignore.txt

I've tried somethings but not works... I'm really stucked with it.

This is my actual project structure:

project-structure

Dockerfile

FROM python:3.11.3-slim-buster

RUN apt-get update && apt-get install \
        --no-install-recommends -qq -y \
    build-essential \
    gcc \
    g++ \
    libpoppler-cpp-dev \
    poppler-utils \
    pkg-config \
    libpq-dev

WORKDIR /project

COPY ./pylintrc /project/pylintrc

COPY ./requirements.txt /project/requirements.txt
COPY ./requirements-dev.txt /project/requirements-dev.txt

RUN pip install --upgrade pip
RUN pip install -r /project/requirements.txt -r /project/requirements-dev.txt

COPY ./alembic.ini /project/alembic.ini
COPY ./alembic /project/alembic
COPY ./athena /project/athena

compose.yaml

services:
  database:
    image: postgres:12
    restart: always
    # command: postgres -c 'max_connections=300'
    container_name: athena-database-container
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
       - postgres:/var/lib/postgresql/data
    ports:
      - "7999:5432"

  alembic:
    build: .
    container_name: athena-alembic-container
    env_file: compose.env
    depends_on:
      - database
    image: athena-project
    command: bash -c "
      sleep 1 &&\
      alembic upgrade head"
    volumes_from:
      - database
    profiles:
      - migrate
    
  api:
    build: .
    container_name: athena-api-container
    # restart: on-failure
    env_file: compose.env
    depends_on:
      - alembic
    image: athena-project
    ports:
      - "8000:8000"
    volumes:
    - ./athena:/project
    command: bash -c "
      sleep 3 &&\
      uvicorn api.main:api --reload --workers 1 --host 0.0.0.0 --port 8000"

  app:
    build: .
    container_name: athena-app-container
    # restart: on-failure
    env_file: compose.env
    depends_on:
      - api
    image: athena-project
    ports:
      - "8001:8001"
    volumes:
    - ./athena:/project
    command: bash -c "
      sleep 4 &&\
      uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8001"

volumes:
  postgres:
Daniel Bailo
  • 127
  • 1
  • 6
  • 2
    Yes, the `volumes:` mount hides absolutely everything in the image's `/project` directory; you're not really using anything from the image in this setup. I'd recommend deleting the `volumes:` and the `command:` override from the Compose file to use the files and default `CMD` built into the image; use a virtual environment without Docker for day-to-day development. – David Maze May 06 '23 at 15:59
  • 1
    From the looks of it: yes. The whole directory `./athena` (host) is mounted to (and thus effectively hides the original content of) `/project` (container). – Turing85 May 06 '23 at 15:59

0 Answers0