Docker Image - Skipping project, because it was not found - dockerfile

My Project directory view is in this image
When I am trying to create image for Srv.OAuth project by keeping the Dockerfile in the main directory of this project getting the following error:
Skipping project "/Lib.Communication/Lib.Communication.csproj" because it was not found.
Skipping project "/Lib.Database/Lib.Database.csproj" because it was not found.
Docker Command :
FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app
COPY Libraries/Lib.Database.csproj ./
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Srv.OAuth.dll"]
Output of the execution :
D:\xxx\xyz\abc\Srv.OAuth>docker image build -f Dockerfile -t almsoauth .
Sending build context to Docker daemon 2.016MB
Step 1/10 : FROM microsoft/dotnet:2.1-sdk AS build-env
---> b23b0e275fcd
Step 2/10 : WORKDIR /app
---> Running in a0b396e6b4be
Removing intermediate container a0b396e6b4be
---> 43a54eff5619
Step 3/10 : COPY *.csproj ./ ---> 0cb2208057f7
Step 4/10 : RUN dotnet restore ---> Running in a9ab75a03390 Skipping project "/Lib.Communication/Lib.Communication.csproj" because it was not found.
Skipping project "/Lib.Database/Lib.Database.csproj" because it was not found.

Related

Failing to CodeDeploy ASP.NET Core Web API Dockerized Container to AWS Elastic Beanstalk: File copy errors

The following is my Dockerfile, located in my startup project's folder MyProjectWebApi:
MyProjectWebApi/Dockerfile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["MyProjectWebAPI/MyProjectWebAPI.csproj", "MyProjectWebAPI/"]
RUN dotnet restore "MyProjectWebAPI/MyProjectWebAPI.csproj"
COPY . .
WORKDIR "/src/MyProjectWebAPI"
RUN dotnet build "MyProjectWebAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyProjectWebAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyProjectWebAPI.dll"]
buildspec.yml:
version: 0.2
phases:
pre_build:
commands:
- dotnet restore
build:
commands:
- dotnet publish -o output
- mkdir build
- cp -R output build/output
- cp HelenWebAPI/Dockerfile build/Dockerfile
artifacts:
files:
- '**/*'
base-directory: build
When I try deploying my code to AWS Elastic Beanstalk, I get the following error:
Error: failed to build docker image: Command /bin/sh -c docker build -t aws_beanstalk/staging-app /var/app/staging/ failed with error exit status 1.
Stderr:COPY failed: file not found in build context or excluded by .dockerignore: stat MyProjectWebAPI/MyProjectWebAPI.csproj: file does not exist
I'm using the Dockerfile generated by Visual Studio 2022.

Dockerfile weird paths generated by Visual Studio

I'm using Jason Taylor's Clean Architecture template and I wonder why his WebUI Dockerfile is generated by Visual Studio just like below.
It sets WORKDIR to /src and then copies each project from /src/ProjectDir/Project.csproj. What's the point of WORKDIR in that case? Look at WORKDIR "/src/src/WebUI". Why /src/src? There is only one src directory.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
WORKDIR /src
COPY ["src/WebUI/WebUI.csproj", "src/WebUI/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]
I suspect this is because WORKDIR /src will create a directory called /src AND change directories into it. After changing into it, it will copy files from the host's relative src folder and into another subdirectory called src (on the container). So the full absolute path becomes /src/src. You can confirm this by adding RUN pwd && ls before the WORKDIR and after the first COPY.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
RUN pwd && ls /
WORKDIR /src
COPY ["src/WebUI/WebUI.csproj", "src/WebUI/"]
RUN pwd && ls
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]

Google Cloud Run: COPY fails when changing source folder from ./ to build

$ gcloud builds submit --tag gcr.io/projectname/testserver
// ... works fine until the COPY step:
Step 6/7 : COPY build ./
COPY failed: stat /var/lib/docker/tmp/docker-builder653325957/build: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
That build folder listed above, /var/lib/docker/tmp/docker-builder653325957/build, is not a local folder. Does Cloud Builder create a temp folder in that format?
How do I get it to copy my local build folder?
I also tried COPY ./build ./ but the CLI output was the same
Dockerfile below.
FROM node:12-slim
# Create app folder
WORKDIR /usr/src/app
# Install app deps. Copy the lock file
COPY package*.json ./
RUN npm install
ENV SCOPES=removed \
SHOPIFY_API_KEY=removed \
SHOPIFY_API_SECRET=removed \
CLIENT_APP_URL=removed
COPY build ./
CMD ["node", "server.js"]
The gcloud command uses the .gitignore and .gcloudignore files to determine which files and directories to include with the Docker build. If your build directory is listed in either of these files, it won't be available to copy into your container image.

npm run build does not create build directory on elasticbeanstalk

I am still puzzled as to why the npm run build command on an elasticbeanstalk instance does not produce the build folder when when I build the dockerfile. Its definitely not a permissions issue as I can mkdir and touch new directory and file respectively. I even list it in the dockerfile and I can confirm that the build folder isn't there.
Also the npm install works and I cal see all the installed libraries in there
However when I build the same dockerfile locally, I can see that it creates a build folder. So its definetely an environment issue. I read somewhere that sometimes npm install can time out on t2.micro. So I even upgraded to t2.small. Still the issue persists.
Can someone help me figure out as to what is going on here ?
Below is my dockerfile
FROM node:alpine as builder
WORKDIR '/app'
COPY package.json ./
RUN npm install
COPY ./ ./
RUN ls
RUN pwd
CMD ["npm", "run" ,"build"]
RUN mkdir varun
RUN touch var
RUN ls
FROM nginx
EXPOSE 80
RUN pwd
COPY --from=builder ./app/build /usr/share/nginx/html
Below are the elasticbeanstalk logs
i-0276e4b74ee15c98f Severe 29 minutes 18 -- -- -- -- -- -- -- -- -- -- 0.03 0.28 0.2 0.1 99.7 0.0
Application update failed at 2018-12-29T06:18:23Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/03build.sh failed.
cat: Dockerrun.aws.json: No such file or directory
cat: Dockerrun.aws.json: No such file or directory
cat: Dockerrun.aws.json: No such file or directory
alpine: Pulling from library/node
7fc670963d22: Pull complete
Digest: sha256:d2180576a96698b0c7f0b00474c48f67a494333d9ecb57c675700395aeeb2c35
Status: Downloaded newer image for node:alpine
Successfully pulled node:alpine
Sending build context to Docker daemon 625.7kB
Step 1/15 : FROM node:alpine as builder
---> 9036ebdbc59d
Step 2/15 : WORKDIR '/app'
---> Running in e623a08307d5
Removing intermediate container e623a08307d5
---> b4e9fe3e4b82
Step 3/15 : COPY package.json ./
---> cb5e6a9b109b
Step 4/15 : RUN npm install
---> Running in 8a00eb1143a5
npm WARN
Removing intermediate container 8a00eb1143a5
---> c568ef0a4bc3
Step 5/15 : COPY ./ ./
---> cfb3e22fc373
Step 6/15 : RUN ls
---> Running in f6aad2a0f22e
Dockerfile
Dockerfile.dev
README.md
docker-compose.yml
node_modules
package-lock.json
package.json
public
src
Removing intermediate container f6aad2a0f22e
---> 016d1ded2f97
Step 7/15 : RUN pwd
---> Running in eaae644b1d96
/app
Removing intermediate container eaae644b1d96
---> 61285a5062ea
Step 8/15 : CMD ["npm", "run" ,"build"]
---> Running in 5cbca2213f4f
Removing intermediate container 5cbca2213f4f
---> 8566953eebaa
Step 9/15 : RUN mkdir varun
---> Running in a078760b6dcb
Removing intermediate container a078760b6dcb
---> 34c25b5aab32
Step 10/15 : RUN touch var
---> Running in d725dafc9409
Removing intermediate container d725dafc9409
---> 70195ffecb54
Step 11/15 : RUN ls
---> Running in b96bc198883c
Dockerfile
Dockerfile.dev
README.md
docker-compose.yml
node_modules
package-lock.json
package.json
public
src
var
varun
Removing intermediate container b96bc198883c
---> 1b205ffb5e3f
Step 12/15 : FROM nginx
latest: Pulling from library/nginx
bbdb1fbd4a86: Pull complete
Digest: sha256:304008857c8b73ed71fefde161dd336240e116ead1f756be5c199afe816bc448
Status: Downloaded newer image for nginx:latest
---> 7042885a156a
Step 13/15 : EXPOSE 80
---> Running in 412e17c44274
Removing intermediate container 412e17c44274
---> e1e1ea0c7dfb
Step 14/15 : RUN pwd
---> Running in 1bc298a11ef1
/
Removing intermediate container 1bc298a11ef1
---> 291575f13e2f
Step 15/15 : COPY --from=builder ./app/build /usr/share/nginx/html
COPY failed: stat /var/lib/docker/devicemapper/mnt/e2b112f1a046c00990aa6fc01e9fabc9e147420a214682a06637ef8cbcb9414a/rootfs/app/build: no such file or directory
Failed to build Docker image aws_beanstalk/staging-app, retrying...
Sending build context to Docker daemon 625.7kB
Oh my god..Finally after 1 full day of tinkering everything on aws, figured it out. I was using CMD instead of RUN to execute the command npm run build. CMD doesn't actually run it when you are building a dockerfile. So the folder isn't actually there for my second image to use.

Dockerfile run python command not working

I have a dockerfile like this:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
ADD reports /code/
RUN pip install -r requirements.txt
ADD . /code/
RUN ls -l /code/reports/report/manage.py # gives expected result
RUN ls -l /code/reports/build_static/ # gives expected result
RUN python /code/reports/report/manage.py build full_report.views.RenderView # does not work
Everything works fine except for the last command which runs a python package (django-bakery) through manage.py build. I don't get any errors.
This command should output some files inside build_static directory in the container.
If I ssh into the container and run the command manually then it is working. I inserted the full path with /code/ to make sure that they match and created all necessary directories beforehand.
This is how I build the container:
docker-compose run django /bin/bash
This is my docker-compose:
version: '3'
services:
django:
build: .
volumes:
- .:/code
ports:
- "8000:8000"
I wonder how come it is working when I run the command manually through bash inside the container, but not working with the command in the dockerfile.
Thanks!
Update (it seems that the files are created, but then if I check on them they aren't there):
Step 12/12 : RUN ls -l /code/reports/build_static/
---> Running in e294563d26d5
total 11080
-rw-r--r-- 1 root root 11339956 Apr 30 10:53 index.html
drwxr-xr-x 7 root root 4096 Apr 30 10:53 static
Removing intermediate container e294563d26d5
---> b8e72da8ee5c
Successfully built b8e72da8ee5c
Successfully tagged image_django:latest
WARNING: Image for service django was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
root#7483853ecc45:/code# ls -l reports/build_static/
total 0
Try following steps and let me know output:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
ADD reports /code/
RUN pip install -r requirements.txt
ADD . /code/
RUN ls -l /code/reports/report/manage.py # gives expected result
RUN ls -l /code/reports/build_static/ # gives expected result
RUN python /code/reports/report/manage.py build full_report.views.RenderView
RUN ls -l /code/reports/build_static/ # should give you expected list of files
Give me output for the last step.
I'll help you out based on output.
The following Dockerfile, copies your current directory content to a code folder (if it doesn't exist, it creates it), then sets it as the workdir.
The WORKDIR instruction sets the working directory for any RUN, CMD,
ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile
Then, in order to reduce you docker image size to the maximum, we regroup all your commands in one RUN command so that it reduces the number of layers.
FROM python:3
ENV PYTHONUNBUFFERED 1
COPY . /code
WORKDIR /code
RUN pip install -r requirements.txt && \
ls -l reports/report/manage.py && \
ls -l reports/build_static/ && \
python reports/report/manage.py build full_report.views.RenderView
I haven't tried it with a full Django app example, but it should help you narrow down the problem !