Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awesomebytes/16d0a5fcc4f368a43ac21e5cf3000034 to your computer and use it in GitHub Desktop.
Save awesomebytes/16d0a5fcc4f368a43ac21e5cf3000034 to your computer and use it in GitHub Desktop.
How to enable Docker experimental features in Azure Pipelines (like --squash)

Enable Docker experimental features on Azure Pipelines

I wanted to try the --squash parameter for docker build on the Azure Pipelines platform. I found it to be not enabled by default and a bit tricky to get working. (As of 25/03/2020).

It did work for me doing the following 2 things:

To enable experimental features in the Docker CLI (referred in docker version as Docker Client):

# Your job should have in the variables setting 'DOCKER_CLI_EXPERIMENTAL' set to 'enabled'
    variables:
      # From https://stackoverflow.com/a/60838744 to enable --squash
      # For the Docker client to have experimental features enabled (--squash)
      DOCKER_CLI_EXPERIMENTAL: enabled

Note that the alternative way is to add to/create ~/.docker/config.json {"experimental": "enabled"}. But Azure Pipelines supports that special DOCKER_CLI_EXPERIMENTAL variable.

And then to enable experimental features in the Docker daemon (referred in docker version as Docker Server):

# You 'steps' setting in the job should have (before docker build is called) a script that enables
# the experimental features in the server and then restarts the docker daemon for it to take effect
    steps:
    # from https://thenewstack.io/how-to-enable-docker-experimental-features-and-encrypt-your-login-credentials/
    # To get the server daemon to enable it
    - script: |
        # sudo sed -i '$s/}/,\n"experimental": true\n}/' /etc/docker/daemon.json
        echo '{"experimental": true}' | sudo tee /etc/docker/daemon.json
        sudo systemctl restart docker
        docker version
      displayName: "enable experimental features in Docker server"

Afterwards the output of docker version would be (notice the Experimental: line):

Client:
 Version:           3.0.11+azure
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        eb310fca49568dccd87c6136f774ef6fff2a1b51
 Built:             Tue Mar  3 21:59:52 2020
 OS/Arch:           linux/amd64
 Experimental:      true

Server:
 Engine:
  Version:          3.0.11+azure
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       aa6a9891b0
  Built:            Tue Mar 10 18:53:36 2020
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment