Skip to content

Commit

Permalink
fixes #131: expose docker certs to vm
Browse files Browse the repository at this point in the history
  • Loading branch information
abiosoft committed Feb 9, 2022
1 parent b83875c commit e6150e1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions environment/container/docker/docker.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package docker

import (
"fmt"
"path/filepath"
"time"

"github.com/abiosoft/colima/cli"
"github.com/abiosoft/colima/config"
"github.com/abiosoft/colima/environment"
"github.com/abiosoft/colima/util"
)

// Name is container runtime name.
Expand Down Expand Up @@ -63,6 +67,9 @@ func (d dockerRuntime) Provision() error {
a.Add(d.setupContext)
a.Add(d.useContext)

// docker certs
a.Add(d.copyCerts)

return a.Exec()
}

Expand Down Expand Up @@ -119,3 +126,34 @@ func (d dockerRuntime) Version() string {
version, _ := d.host.RunOutput("docker", "version", "--format", `client: v{{.Client.Version}}{{printf "\n"}}server: v{{.Server.Version}}`)
return version
}

func (d dockerRuntime) copyCerts() error {
log := d.Logger()
err := func() error {
dockerCertsDirHost := filepath.Join(util.HomeDir(), ".docker", "certs.d")
dockerCertsDirGuest := "/etc/docker/certs.d"
if _, err := d.host.Stat(dockerCertsDirHost); err != nil {
// no certs found
return nil
}

// we are utilising the host cache path as it is the only guaranteed mounted path.

dockerCertsCacheDir := filepath.Join(config.CacheDir(), "docker-certs")
if err := d.host.RunQuiet("mkdir", "-p", dockerCertsCacheDir); err != nil {
return err
}

if err := d.guest.RunQuiet("sudo", "mkdir", "-p", dockerCertsDirGuest); err != nil {
return err
}

return d.guest.RunQuiet("sudo", "cp", "-R", dockerCertsCacheDir+"/.", dockerCertsDirGuest)
}()

// not a fatal error, a warning suffices.
if err != nil {
log.Warnln(fmt.Errorf("cannot copy docker certs to vm: %w", err))
}
return nil
}

0 comments on commit e6150e1

Please sign in to comment.