-
Create a new repsitory
container-demo
and add a new file namend Dockerfile (without extension). Add the following content:FROM alpine CMD ["echo", "Hello World!"]
If you want to test this locally, clone your repository and change directory to it. Build and run the image. The output is
Hello World!
:$ docker build -t container-demo . $ docker run --rm container-demo > Hello World!
-
Create a workflow file
.github/workflows/release-container.yml
with the following content and commit/push it to your repository:name: Publish Docker image on: release: types: [published] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build-and-push-image: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v2 - name: Log in to the Container registry uses: docker/[email protected] with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/[email protected] with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Build and push Docker image uses: docker/[email protected] with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}
-
The workflow gets triggered if you publish a new release. Navigate to
Source
and click onCreate a new release
: -
Enter
v1.0.0
as atag
and hit enter: -
Enter a name for the release and publish it:
-
If the workflow has completed you can see the
container-demo
package underCode
|Packages
. Click on it to see details: -
To test the image, pull it from the library and run it:
$ docker pull ghcr.io/<github-user>/container-demo:latest $ docker run --rm ghcr.io/<github-user>/container-demo:latest > Hello World!