问题
In continuation of my previous question
I am trying to build and push a docker image to Amazon ECR with GitHub Actions by following this tutorial
But I am getting the following error :
Run docker build \
unable to prepare context: path " " not found
Can anyone help me resolve this issue??
Edit 1:
As stated by @banyan I have created an app
directory
But still I am getting the same error.
To know more, please go through this
回答1:
There is issue in this line of your dockerfile:
docker build \
-t $CONTAINER_IMAGE \
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE ./app
docker build
command syntax is :
docker build [OPTIONS] PATH | URL | -
If we use -t
option then we specify container image name.
In the above command since you have used two -t
options so after first -t
everything is used as path to dockerfile which is wrong, because of which this error is coming unable to prepare context: path " " not found
.
So, the correct syntax should be:
docker image build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE ./app
.
This is the modified Dockerfile :
name: Building and pushing a docker image to Amazon ECR
on: [push, pull_request]
env:
AWS_DEFAULT_REGION: ap-southeast-1
AWS_DEFAULT_OUTPUT: json
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CONTAINER_IMAGE: myimage:${{ github.sha }}
jobs:
build-and-push:
name: Building and pushing image to AWS ECR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup ECR
run: |
$( aws ecr get-login --no-include-email )
- name: Build and tag the image
run: |
docker image build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE ./app
- name: Push
if: github.ref == 'refs/heads/master'
run: |
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE
Have forked your project and ran the same. Build and tag image step ran successfully on Git Actions.
It is failing in next step i.e. Push step with error as
The repository with name 'myimage' does not exist in the registry with id '***'
.
For this you need to create image repository in ECR container registry. You can refer to this answer for the same Push docker image to amazon ecs repository
回答2:
❯ docker build " "
unable to prepare context: path " " not found
I think the article expects ./app/Dockerfile
to run docker build
. but there's no app directory so the action can not run.
来源:https://stackoverflow.com/questions/60611165/error-unable-to-prepare-context-path-not-found-while-building-and-tagging