Pete Freitag Pete Freitag

Writing a GitHub Actions Workflow that Uses a Docker Image


When working with Github Actions there are a few different ways to write a workflow yaml that uses a docker image or a docker container.

Using uses

The easiest way you can use a docker container in your GitHub Actions workflow is with the uses option. This is combined with a docker URI, here's an example Github Actions Job that uses docker:

    runs-on: ubuntu-latest
    - uses: actions/[email protected]
    - name: Run box version	    
      uses: docker://foundeo/minibox:latest
        entrypoint: /opt/box/box
        args: version

In this example we tell GitHub Actions that this job uses the docker image foundeo/minibox:latest. You can also specify an entrypoint (the command to run inside the container) and args (command line arguments to pass to the command specified in entrypoint). You might be able to omit entrypoint if the container already species the entrypoint you want to use.

Can the Docker Container Access My Github Code?

This was a question I had when I first started playing with GitHub Actions. It turns out, you can access your github repository code because when the workflow job executes uses: docker://container it also mounts a volume, and passes several environment variables. The GitHub Actions workflow workspace is mounted to the path: /github/workspace/

Note that the code checked out of our github repository because we ran uses: actions/[email protected] as a prior step.

Another way to use a docker image

Another way to go run commands inside a docker image as part of your Github Actions workflow is to use the container and image options. Here's an example of specifying a docker image in the workflow yaml:

    runs-on: ubuntu-latest
      image: azul/zulu-openjdk-alpine:8-jre
    - uses: actions/[email protected]
    - name: What OS is running
      run: uname -a
    - name: What java version do we have
      run: java -version

In this example we are running multiple commands inside the container image. In this case we are running Java / OpenJDK inside an Alpine Linux container.

Hopefully you find these examples useful to show the different ways you can run inside a docker container as part of your GitHub Actions workflow.

Like this? Follow me ↯

Writing a GitHub Actions Workflow that Uses a Docker Image was first published on May 14, 2020.

If you like reading about docker, git, github, or ci then you might also like:


I ran the second example with and without the container command and the results were the same. How do I know the steps were run in the container?
by Jason on 02/02/2021 at 4:14:04 PM UTC
Jason - you should have different output, eg when running in the container the java version will contain: "Zulu" when running without a container the default java would be "AdoptOpenJDK"
by Pete Freitag on 07/29/2021 at 8:53:09 PM UTC
Hi Pete,

while using docker in a step should the image be a public docker image. Can i use an image from local repostiory or private repostiory if yes , how do I pass the auth info?

also is there any way that we can use a local image that is already pulled, in case we cannot pull the image from the private CR.
by Gopi on 02/04/2022 at 7:25:15 AM UTC
Hi Gopi

You can use a private dockerhub image, you just have to add under secrets your docker username and password, the code is like this :
image: id/img:version
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

by Issam on 03/02/2022 at 2:23:07 PM UTC

Post a Comment