collimarco
collimarco

Reputation: 35460

How to install docker on GitHub Actions

What is the official / recommended way to install Docker on GitHub Actions?

In particular I need to run a custom script on GitHub Actions that, among other tasks, calls docker build and docker push.

I don't want pre-made actions that build/push, I want to have access to the docker command.

What should I do?

The only official action that I can find uses Docker Buildx and not the normal docker: https://github.com/marketplace/actions/build-and-push-docker-images

Beside that I can find this action (https://github.com/marketplace/actions/setup-docker) but I don't know if I can trust that source, since it's not official.

Any recommendations? How do you install the docker command on GitHub Actions?

Upvotes: 11

Views: 15013

Answers (2)

Grey Vugrin
Grey Vugrin

Reputation: 658

Although Docker is available on default ubuntu images, you may want to install it on your own self-hosted runners, or on images that don't have it preinstalled. There is an official action from Docker for that: https://github.com/docker/setup-docker-action

As of Jan 2025, this is the recommended quick-start snippet to set it up, regardless of distro (as long as you're running one of the supported ones - see the repo for that.)

name: ci

on:
  push:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker
        uses: docker/setup-docker-action@v4

Note: please go directly to the repo to confirm! You'll want the latest guidance from them and the latest available version of the action.

Upvotes: 0

Jallrich
Jallrich

Reputation: 469

Docker is already available in the default ubuntu images.

You can find all the installed software in actions/runner-images.

It looks like Windows and Mac images do not have the Docker client installed: Search results.

This is a valid CI that I use in my workflow:

name: Check that image builds
on:
  pull_request:

jobs:
  test-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Check that the image builds
        run: docker build . --file Dockerfile

Upvotes: 3

Related Questions