user10336820
user10336820

Reputation:

Why doesn't docker compose create container with container_name

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

Upvotes: 1

Views: 166

Answers (1)

Ralle Mc Black
Ralle Mc Black

Reputation: 1203

Just execute:

docker compose up

inside the folder which contains docker-compose.yaml

Or -f pathToYourDockerComposeFile

Upvotes: 0

Related Questions