How to use docker-api with go modules

You’re trying to use client.NewClientWithOpts from module and you can’t find it? Getting client.NewClientWithOpts not declared by package client?

I’ve been there, and fix is relatively easy:

  1. First add this line to your go.mod file:
    // force go mod to pull proper package for docker
    replace => v0.0.0-20191113042239-ea84732a7725

    This tells go modules to replace references to docker/docker with docker/engine - where the module is really stored.

  2. Make sure that your go.mod file references proper packages. In my case it was replacing references with the ones to github: v1.13.1 v0.4.0

Voilà - go resolves proper docker api client package now.