Sam B.
Sam B.

Reputation: 3033

Docker ERROR: Couldn't find env file: /home/sam/code/docker/.env.dev

I'm learning how to use docker with Django. So first step is you setup the Dockerfile and here's the content of the file.

FROM python:3.8.0-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

# copy project
COPY . /usr/src/app/

another file the docker-compose.yml file content below

version: '3.7'

services:
  web:
    build: ./project
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./project/:/usr/src/app/
    ports:
      - 8000:8000
    env_file:
      - ./.env.dev

now these two files are in the folder docker which also has my django project folder called project keeping it simple :)

When I run docker-compose build I get back the error

ERROR: Couldn't find env file: /home/sam/code/docker/.env.dev

Upvotes: 5

Views: 33789

Answers (1)

Janitha Tennakoon
Janitha Tennakoon

Reputation: 906

You are specifying that .env file can be found in the location where your docker-compose.yml file is located.

env_file:
  - ./.env.dev

Make sure that your .env file is available there. If you don't need any environment variables to be set just remove above line from the docker-compose.yml file.

Upvotes: 12

Related Questions