Skip to content

Commit

Permalink
containerd: add socket forwarding to host (#1017)
Browse files Browse the repository at this point in the history
* Added containerd socket port forward when using containerd runtime

* Added comment to "HostSocketFile" function in containerd.go
  • Loading branch information
DieterBuys authored Apr 16, 2024
1 parent 17312bd commit de7af47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions environment/container/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package containerd
import (
"context"
_ "embed"
"path/filepath"
"time"

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

// Name is container runtime name
const Name = "containerd"

// HostSocketFile returns the path to the containerd socket on host.
func HostSocketFile() string { return filepath.Join(config.Dir(), "containerd.sock") }

// This is written with assumption that Lima is the VM,
// which provides nerdctl/containerd support out of the box.
// There may be need to make this flexible for non-Lima VMs.
Expand Down
11 changes: 11 additions & 0 deletions environment/vm/lima/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/abiosoft/colima/config"
"github.com/abiosoft/colima/environment"
"github.com/abiosoft/colima/environment/container/containerd"
"github.com/abiosoft/colima/environment/container/docker"
"github.com/abiosoft/colima/util"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -198,6 +199,16 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) {
}
}

// containerd socket
if conf.Runtime == containerd.Name {
l.PortForwards = append(l.PortForwards,
PortForward{
GuestSocket: "/var/run/containerd.sock",
HostSocket: containerd.HostSocketFile(),
Proto: TCP,
})
}

// handle port forwarding to allow listening on 0.0.0.0
// bind 0.0.0.0
l.PortForwards = append(l.PortForwards,
Expand Down

0 comments on commit de7af47

Please sign in to comment.