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!
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With