1

I created a Dockerfile and docker-compose.yml file.

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. Compose doesn't create another container with "container_name: money". Why doesn't the second "container_name" work?

output in terminal, lsc is an alias of docker container ls -a

2
  • 1
    Please don't paste picture URLs here. It's text that can be rendered nicely here. Commented Jan 20, 2023 at 14:27
  • 2
    How did you start your containers? By the container name money-mangement_web_run_... I'm led to believe you ran docker compose run Commented Jan 20, 2023 at 14:29

1 Answer 1

0

Just execute:

docker compose up

inside the folder which contains docker-compose.yaml

Or -f pathToYourDockerComposeFile

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.