How to enable experimental features for Docker in Github's workflow for Ubuntu 18.04?

If you’re using Github’s workflows for CI/CD and you need to use some of Docker’s experimental features, or you want to use buildx or maybe you just want to use some of the new dockerfile experimental syntaxes then you need to enable the experimental features for the CLI and probably the daemon too.

When running natively on Linux or macOS, it’s pretty easy.

To enable the experimental features for the CLI, you just need to add the following to your ~/.docker/config.json config:

1
2
3
{
  "experimental": "enabled"
}

And to enable the experimental features for the daemon, you need to add the following to your /etc/docker/daemon.json config:

1
2
3
{
  "experimental": true
}

The Github workflow setup is no different:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
name: Stuff builder
on:
  push:
    branches:
      - master

jobs:
  build-stuff:
    runs-on: ubuntu-18.04
    steps:
      - name: Enable experimental features for the Docker daemon and CLI
        run: |
          echo $'{\n  "experimental": true\n}' | sudo tee /etc/docker/daemon.json
          mkdir -p ~/.docker
          echo $'{\n  "experimental": "enabled"\n}' | sudo tee ~/.docker/config.json
          sudo service docker restart
          docker version -f '{{.Client.Experimental}}'
          docker version -f '{{.Server.Experimental}}'
          docker buildx version          

That’s pretty much it. See it in action at rolandjitsu/docker-ssh.