use env vars to determine the docker API version (closes #71)

This commit is contained in:
Alex Goodman 2018-11-24 20:48:31 -05:00
parent 6a6cbe1be9
commit 7d868096ca
No known key found for this signature in database
GPG Key ID: 743640FAA11698A1
3 changed files with 13 additions and 18 deletions

View File

@ -88,7 +88,6 @@ When running you'll need to include the docker client binary and socket file:
```bash
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/bin/docker \
wagoodman/dive:latest <dive arguments...>
```
@ -96,7 +95,18 @@ Docker for Windows (showing PowerShell compatible line breaks; collapse to a sin
```bash
docker run --rm -it `
-v /var/run/docker.sock:/var/run/docker.sock `
-v /usr/local/bin/docker:/bin/docker `
wagoodman/dive:latest <dive arguments...>
```
**Note:** depending on the version of docker you are running locally you may need to specify the docker API version as an environment variable:
```bash
DOCKER_API_VERSION=1.37 dive ...
```
or if you are running with a docker image:
```bash
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_API_VERSION=1.37
wagoodman/dive:latest <dive arguments...>
```

View File

@ -199,12 +199,10 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree, float64, fi
var manifest ImageManifest
var layerMap = make(map[string]*filetree.FileTree)
var trees = make([]*filetree.FileTree, 0)
dockerVersion = utils.DiscoverDockerVersion()
logrus.Debug("Using docker version:", dockerVersion)
// pull the image if it does not exist
ctx := context.Background()
dockerClient, err := client.NewClientWithOpts(client.WithVersion(dockerVersion), client.FromEnv)
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
fmt.Println("Could not connect to the Docker daemon:" + err.Error())
utils.Exit(1)

View File

@ -1,7 +1,6 @@
package utils
import (
"bytes"
"os"
"os/exec"
"strings"
@ -31,15 +30,3 @@ func cleanArgs(s []string) []string {
}
return r
}
func DiscoverDockerVersion() string {
cmd := exec.Command("docker", "version", "--format", "{{.Server.APIVersion}}")
cmdOutput := &bytes.Buffer{}
cmd.Stdout = cmdOutput
err := cmd.Run()
if err != nil {
panic(err)
}
return strings.TrimSpace(string(cmdOutput.Bytes()))
}