Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify the dockerfile location in my github action?

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!

like image 894
avenmia Avatar asked Oct 28 '25 10:10

avenmia


2 Answers

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.

like image 76
wwmwabini Avatar answered Oct 29 '25 23:10

wwmwabini


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)
like image 27
Raj Srujan Jalem Avatar answered Oct 30 '25 00:10

Raj Srujan Jalem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!