I have a .Net multi-project solution that I’m containerizing and I’m trying to automate the build with Github Actions.
This is a simplified overview of my file structure:
repo/
├── Solution.sln
└── src/
├── Core/
│ └── Project.Domain/
│ └── Project.Domain.csproj
└── Presentation/
└── Project.API/
├── Project.API.csproj
└── Dockerfile
The API project depends on the Domain project (among others in reality) and it won’t be the only containerized project in the solution, so there will be multiple Dockerfiles.
This is the beginning of my Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /App
COPY ../../../ ./
# The reset of the build steps...
When I build the container locally (Git Bash on Windows with Docker Desktop) using the following command, it passes:
$ pwd
/path/to/repo
$ docker build -f ./src/Presentation/Project.API/Dockerfile .
I have a github workflow to automate that, this is the workflow file:
name: Dev Deployment
on:
push:
branches:
- 'main'
jobs:
deploy:
name: Deploy API
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
run: |
docker build -f ./src/Presentation/Project.API/Dockerfile .
I get the following error:
Step 3/11 : COPY ../../../ ./
COPY failed: forbidden path outside the build context: ../../../ ()
How do I fix this and why does it work on Windows but not in the Action?
2
Answers
You could try using the
working-directory
keyword, you can specify the working directory of where to run the command. As example:or just change directory before running the command
Assuming that the execution does currently reside in
/repo
(i.e.pwd
is/repo
), theCOPY
-directive in theDockerfile
is wrong. The host-path of theCOPY
is always relative to the context, not theDockerfile
(just like the contaier-path is relative to theWORKDIR
). Henceshould be