Ali Coskun
Ali Coskun

Reputation: 25

docker-compose ERROR: Cannot locate specified Dockerfile

I have a .Net Core project that I want to deploy production environment but when I try to build it on my droplet I get this error "ERROR: Cannot locate specified Dockerfile". I couldn't figure out what's wrong with my configurations.

Project Structure

project
│   project.sln
│   docker-compose.dcproj  
│   docker-compose.dev.yml
│   docker-compose.prod.yml 
│   docker-compose.yml
│
└───project.Web
│   │   (mvc-files)
│   │   .dockerignore
│   │   Dockerfile
│   │   project.Web.csproj
│   │
│   
└───project.Models
│
└───project.Services
│
└───project.Core

Dockerfile

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY project.Web/project.Web.csproj project.Web/
COPY project.Models/project.Models.csproj project.Models/
COPY project.Services/project.Services.csproj project.Services/
COPY project.Core/project.Core.csproj project.Core/
RUN dotnet restore project.Web/project.Web.csproj
COPY . .

WORKDIR /src/project.Web
RUN dotnet build project.Web.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish project.Web.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "project.Web.dll"]

docker-compose.yml

version: '3.7'

services:
  webapp:
    build:
      context: .
      dockerfile: project.Web/Dockerfile

I execute these codes on different environments

docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build

This docker-compose works on local environment but doesn't work on prod, can't find Dockerfile. I've checked .dockerignore if it contains Dockerfile but i doesn't. I've tried to execute with these configs but still no luck

 - context: .
   dockerfile: project.Web/Dockerfile

 - context: .
   dockerfile: Dockerfile

 - context: app/
   dockerfile: Dockerfile

 - context: app/project.Web/
   dockerfile: Dockerfile

EDIT: I didn't think dev or prod docker-compose file is the problem but adding anyway.

docker-compose.dev.yml

version: '3.7'

networks:
  network-dev:
    driver: bridge

services:
  webapp:
    image: project
    container_name: container-webapp
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://+:80
    networks:
      - "network-dev"
    ports:
      - "80"
    depends_on:
      - "db"

  db:
    image: postgres:latest
    container_name: container-db
    environment: 
      - "POSTGRES_USER=username"
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_DB=projectdb"
    restart: always
    ports:
      - "13650:5432"
    networks:
      - "network-dev"

docker-compose.prod.yml

version: '3.7'

networks:
  network-prod:
    driver: bridge

services:
  webapp:
    image: alicoskun/project:latest
    container_name: container-webapp
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_URLS=http://+:80
    networks:
      - "network-prod"
    ports:
      - "80"
    depends_on:
      - "db"

  db:
    image: postgres:latest
    container_name: container-db
    environment: 
      - "POSTGRES_USER=username"
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_DB=projectdb"
    restart: always
    ports:
      - "13650:5432"
    networks:
      - "network-prod"

Upvotes: 2

Views: 1896

Answers (1)

Steve Boyd
Steve Boyd

Reputation: 1357

Assuming you have already pushed the alicoskun/project:latest image into a repository where your production droplet can find it, you have no need to include the docker-compose.yml file as part of your docker-compose command. Instead, just run:

docker-compose -f docker-compose.prod.yml up -d --build

Including the docker-compose.yml in your docker-compose command-line will require that the Dockerfile be present, even though it will not be used to build the system.

Upvotes: 1

Related Questions