docker-compose ERROR: Cannot locate specified Dockerfile - docker

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"

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.

Related

How to resolve dockerfile, and docker-compose when main go files are in nested directory?

I am very new to Docker so please forgive me, but I have a working dockerfile and docker-compose when the Main.go is at root-level but in this project the app will break if I put main.go at root.
File Structure
queue-backend
- .idea
- cmd
- appCode
- handler.go
- helper.go
- main.go
- routes.go
- pkg
- forms
- models
- mongodb
- models.go
- tmp
.gitignore
docker-compose.yml
Dockerfile
go.mod
README.md
db
extensions
Anyway... my dockerfile looks like this
FROM golang:1.16
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY ../.. .
RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
CMD ["air"]
Docker-compose.yml looks like
version: '3.9'
services:
backend:
build: ""
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- mongodb_container
mongodb_container:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: queue-delivery
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- 27017:27017
volumes:
- mongodb_data_container:/data/db
volumes:
mongodb_data_container:
I have tried to set WORKDIR to /app/cmd/appCode or /cmd/appCode and matching the same in the docker-compose to .:/app/cmd/appCode and .:/cmd/appCode which none work, it always returns this, or the stated paths above instead of just the '/app' path
backend_1 | no Go files in /app
backend_1 | failed to build, error: exit status 1
At this point, I'm not sure what else to try...
To resolve Dockerfile in docker-compose.yml you need to change the build section as below
version: '3.9'
services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- mongodb_container
mongodb_container:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: queue-delivery
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- 27017:27017
volumes:
- mongodb_data_container:/data/db
volumes:
mongodb_data_container:
Your Dockerfile has some issues,
FROM golang:1.16
WORKDIR /app
# File changes must be added at the very end, to avoid the installation of dependencies again and again
RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
COPY go.mod .
COPY go.sum . # can not find this file in the directory structure
RUN go mod download
COPY ../.. . # doesn't make sense, just use COPY . .
CMD ["air"]

Two Api connection via docker-compose and docker registry

We have one API project with DockerFile
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 43001
EXPOSE 43002
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY Api.csproj Api/
RUN dotnet restore Api/Api.csproj
COPY . .
WORKDIR /src/Api
RUN dotnet build Api.csproj --no-restore -c Release -o /app
FROM build AS publish
WORKDIR /src/Api
RUN dotnet publish Api.csproj --no-restore --no-self-contained -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Api.dll"]
And with docker-compose
version: '3.5'
services:
Api:
image: Api
restart: always
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_ENVIRONMENT=Production
build:
context: .
dockerfile: Api/Dockerfile
ports:
- "43001:80"
- "43002:443"
This project pushed to private docker registry.
And we have second Prod project that should use and connect to Api project.
docker-compose Prod project:
version: '3.5'
services:
Prod:
image: Prod
restart: always
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://+:80
build:
context: .
dockerfile: Prod/Dockerfile
depends_on:
- Api
networks:
- proxy-net
expose:
- "80"
Api:
image: {RegistryAddress}/Api
restart: always
networks:
- proxy-net
ports:
- "43002:443"
networks:
proxy-net:
external:
name: proxy-net
Issue - When I am connecting from Prod to Api I am getting Connection refused. Perhaps something with ports settings, but I tried a lot of changes and it didn`t help. I thought Api ports settings should be enough, but looks like we need to set something in Prod also.

docker with asp.net core error dockerfile run dotnet publish

when i use docker build i receive this error: error image
i've change the relative path on docker file to absolute path changing --from=build-env to bin/Release/netcoreapp3.1/publish/ but when i use docker-compose the error show again
Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "SmartSchool.WebAPI.dll"]
docker-compose
version: "3.8"
volumes:
SmartSchoolDb:
networks:
mysqlNET:
smartschoolNET:
services:
mysql:
image: "mysql:5.7"
container_name: mysql
ports:
- "3306:3306"
volumes:
- SmartSchoolDb:/var/lib/mysql
networks:
- mysqlNET
environment:
- MYSQL_USER=root
- MYSQL_PASSWORD=test
- MYSQL_ROOT_PASSWORD=test
- MYSQL_ROOT_HOST=%
- bind-address:0.0.0.0
smartschool:
build:
context: .
dockerfile: Dockerfile
container_name: smart
networks:
- mysqlNET
- smartschoolNET
ports:
- 5000:80
environment:
- DBHOST=mysql
depends_on:
- mysql
I add .dockerignore created using vscode command ctrl + shift + p and docker: add docker files to workspace
i used this .dockerignore below
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
bin/
obj/
out/
TestResults/

docker-compose doesn't refresh volumes on file changes

I am using Docker Toolbox on Windows 10 Home. I am not able to see the changes in my code on the docker-container.
My docker-compose.yml file looks like this
version: "3.7"
services:
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=MyFlaskApp
expose:
- 8080
volumes:
- ./flask:/app
nginx:
build: ./nginx
container_name: nginx
restart: always
ports:
- "80:80"
And my Dockerfile looks like this
FROM python:3.7.2-stretch
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install the dependencies
RUN pip install -r requirements.txt
# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
My folder structure is like this
-project
- flask
- app.ini
- Dockerfile
- requirements.txt
- run.py
-nginx
- Dockerfile
- nginx.conf
I'm pretty sure everything is in order here but I still can't make live changes to the server

docker invalid reference format

my files strucutre . i have i am building two container one is mysql database
another is python application
docker-compose.yml
version: '3'
services:
mysql-dev:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: *****
MYSQL_DATABASE: vlearn
ports:
- "3308:3308"
app:
image: ./app
ports:
- "5000:5000"
app file
FROM python:3.7
WORKDIR /usr/src/app
COPY . .
RUN pip install pipenv
RUN pipenv install --system --deploy --ignore-pipfile
CMD ["python","app.py"]
When i Run docker-compose up
i get following
Error
Pulling app (./app:)...
ERROR: invalid reference format
my directory structure
├── app
│ ├── Dockerfile
│ ├── Pipfile
│ └── Pipfile.lock
└── docker-compose.yml
app:
build : ./app
ports:
- "5000:5000"
it must be build : ./app instead of image: ./app

Resources