Reputation: 2605
I'm adding a dockerfile to my asp.net core application and it's located in a subdirectory. I'm trying to create a github action to run the dockerfile, but the action is having difficulty finding it. My folder structure is:
api/
|--Data/
|--Service/
|--|--Dockerfile
|--Tests/
|--MyProject.sln
frontend/
My action.yml is:
name: Docker Image CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
When the action runs, I get the following error on the docker build.
Run docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
shell: /bin/bash -e {0}
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/runner/work/MyProject-actions/MyProject-actions/Dockerfile: no such file or directory
##[error]Process completed with exit code 1.
Any help would be appreciated!
Upvotes: 4
Views: 7553
Reputation: 145
Another way to specify the file would be to do the steps parts this way. I copy pasted from my GitHub actions workflow.
steps:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push register app
uses: docker/build-push-action@v3
with:
push: true
file: ./register/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/register:latest
You can check this link https://github.com/docker/build-push-action for more options you can include while building and pushing docker images.
Upvotes: 7
Reputation: 661
There is an issue in this line:
run: docker build ./api/Service/ --file Dockerfile --tag my-image-name:$(date +%s)
The usage of --file
flag is wrong. The correct way would be:
run: docker build --file ./api/Service/Dockerfile --tag my-image-name:$(date +%s)
Upvotes: 6