Why docker compose dosent create container with container_name

i create Dockerfile and docker-compose.yml.

i build image with tag "django-image"

Dockerfile:

FROM python:3

WORKDIR /code-django

COPY . /code-django

RUN pip3 install -r requirements.txt

docker-compose.yml:

services:
  db:
    image: postgres
    container_name: db-money
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  web:
    image: django-image
    container_name: money
    volumes:
      - .:/code-django
    ports:
      - "8000:8000"
    environment:
      - POSTGRES_NAME=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    depends_on:
      - db

in docker compose i have 2 services,"db" and "web". docker compose creates "db" with "container_name: db-money" and starts it. but compose dosent create anothe container with "container_name: money". why the second "container_name" dosent work??

out put in terminal. lsc is a alias (docker container ls -a)

Just execute:

docker compose up

inside the folder which contains docker-compose.yaml

Or -f pathToYourDockerComposeFile

Back to Top