I want to build my image and push it to dockerhub using github actions.This is
CodePudding user response:
You are not having env.IMAGE data. Below piece of code should do the job.
- name: Build and push
run: docker build -t ${{ env.IMAGE }}:${{ github.sha }} .
env:
IMAGE: shirzadi/ehsan
- name: Push it!
run: docker push ${{ env.IMAGE }}:${{ github.sha }}
env:
IMAGE: shirzadi/ehsan
CodePudding user response:
You are using environment variables that don't exist. According to docker/build-push-action@v2 documentation it can build, tag and push your image in a single step:
jobs:
docker:
steps:
# ...
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: shirzadi/ehsan:latest,shirzadi/ehsan:${{ env.GITHUB_SHA }}
The
tags
key lists 2 tags and use theGITHUB_SHA
environment variable. These tags will be pushed as thepush
key is set to true.
See: