From f01b1542ff0a88e5783c98a618770998d4517c0d Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 10:28:30 +0100 Subject: [PATCH 1/8] chore: minor fixes --- README.md | 102 +------------- cmd/nerdctl.go | 13 +- docs/FAQ.md | 177 ++++++++++++++++++++++++ INSTALL.md => docs/INSTALL.md | 0 environment/container/docker/context.go | 3 + environment/vm/lima/yaml.go | 9 ++ 6 files changed, 204 insertions(+), 100 deletions(-) create mode 100644 docs/FAQ.md rename INSTALL.md => docs/INSTALL.md (100%) diff --git a/README.md b/README.md index cc4f43f86..f1d38a121 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Container runtimes on macOS (and Linux) with minimal setup. ### Installation -Colima is available on Homebrew, MacPorts, and Nix. Check [here](INSTALL.md) for other installation options. +Colima is available on Homebrew, MacPorts, and Nix. Check [here](docs/INSTALL.md) for other installation options. ``` # Homebrew @@ -141,105 +141,9 @@ Colima means Containers in [Lima](https://github.com/lima-vm/lima). Since Lima is aka Linux on Mac. By transitivity, Colima can also mean Containers on Linux on Mac. -## FAQ +## FAQs -
-How does Colima compare to Lima? -

- -Colima is basically a higher level usage of Lima and utilises Lima to provide Docker, Containerd and/or Kubernetes. - -If you want more control over the underlying VM, you can either use Lima directly or override Colima's VM settings with [Lima overrides](https://github.com/lima-vm/lima/blob/873a39c6652fe5fcb07ee08418f39ccaeeea6979/pkg/limayaml/default.yaml#L271). - -

-
- -
-Can it run alongside Docker for Mac? -

-Yes, from version v0.3.0 Colima leverages Docker contexts and can thereby run alongside Docker for Mac. - -`docker context list` can list all contexts and `docker context use` can be used to change the active context. - -

-
- -
-How to customize Docker config e.g. add insecure registries? -

- -### v0.3.4 or older - -On first startup, Colima generates Docker daemon.json file at `$HOME/.colima/docker/daemon.json`. - -Simply modify the daemon.json file accordingly and restart Colima. - -### v0.4.0 or newer - -Start Colima with `--edit` flag `colima start --edit` and add the config to the `docker` section. - -To manually modify the config file, it is located at `$HOME/.colima/default/colima.yaml` for the default profile, -, `$HOME/.colima//colima.yaml` for other profiles, and `$HOME/.colima/_templates/default.yaml` for the default -template. - -

-
- -
-How does it compare to minikube, Kind, K3d? -

- -### For Kubernetes - -Yes, you can create a Kubernetes cluster with minikube (with Docker driver), Kind or K3d instead of enabling Kubernetes -in Colima. Those are better options if you need multiple clusters, or do not need Docker and Kubernetes to share the -same images and runtime. - -### For Docker - -Minikube with Docker runtime can expose the cluster's Docker with `minikube docker-env`. But there are some caveats. - -- Kubernetes is not optional, even if you only need Docker. - -- All of minikube's free drivers for macOS fall-short in one of performance, port forwarding or volumes. While - port-forwarding and volumes are non-issue for Kubernetes, they can be a deal breaker for Docker-only use. - -### Compatibility - -Colima with Docker runtime is compatible with Kind and K3d. - -

-
- -
-Are M1 macs supported? -

- -Colima supports and works on M1 macs but not rigorously tested as the author do not currently possess an M1 device. -Feedbacks would be appreciated. - -

-
- -
-Can I set default configurations? -

- -Yes, via the `template` command. - -``` -colima template -``` - -Use a preferred editor by setting `$EDITOR` or passing the `--editor` flag - -```sh -colima start --edit --editor code # one-off edit -colima template --editor code # set the default config -``` - -

-
+Check [here](docs/FAQ.md) for Frequently Asked Questions. ## Help Wanted diff --git a/cmd/nerdctl.go b/cmd/nerdctl.go index dd44bf08f..2185723fd 100644 --- a/cmd/nerdctl.go +++ b/cmd/nerdctl.go @@ -97,7 +97,7 @@ var nerdctlLinkFunc = func() *cobra.Command { Profile string }{ ColimaApp: os.Args[0], - Profile: strings.TrimPrefix(config.Profile().ID, "colima-"), + Profile: config.Profile().ShortName, } var buf bytes.Buffer if err := t.Execute(&buf, values); err != nil { @@ -112,6 +112,9 @@ var nerdctlLinkFunc = func() *cobra.Command { return fmt.Errorf("error backing up existing file: %w", err) } } + if err := os.MkdirAll("/usr/local/bin", 0755); err != nil { + return nil + } return os.WriteFile(nerdctlCmdArgs.path, buf.Bytes(), 0755) } @@ -123,6 +126,14 @@ var nerdctlLinkFunc = func() *cobra.Command { return fmt.Errorf("error backing up existing file: %w", err) } } + // prepare dir + { + c := cli.CommandInteractive("sudo", "mkdir", "-p", "/usr/local/bin") + if err := c.Run(); err != nil { + return err + } + } + // install script { c := cli.CommandInteractive("sudo", "sh", "-c", "cat > "+nerdctlCmdArgs.path) c.Stdin = &buf diff --git a/docs/FAQ.md b/docs/FAQ.md new file mode 100644 index 000000000..15e56017e --- /dev/null +++ b/docs/FAQ.md @@ -0,0 +1,177 @@ +# FAQs + +- [FAQs](#faqs) + - [How does Colima compare to Lima?](#how-does-colima-compare-to-lima) + - [Are M1 macs supported?](#are-m1-macs-supported) + - [Can config file be used instead of cli flags?](#can-config-file-be-used-instead-of-cli-flags) + - [Editing the config](#editing-the-config) + - [Setting the default config](#setting-the-default-config) + - [Specifying the config editor](#specifying-the-config-editor) + - [Docker](#docker) + - [Can it run alongside Docker for Mac?](#can-it-run-alongside-docker-for-mac) + - [Listing Docker contexts](#listing-docker-contexts) + - [Changing the active Docker context](#changing-the-active-docker-context) + - [How to customize Docker config e.g. add insecure registries?](#how-to-customize-docker-config-eg-add-insecure-registries) + - [How does Colima compare to minikube, Kind, K3d?](#how-does-colima-compare-to-minikube-kind-k3d) + - [For Kubernetes](#for-kubernetes) + - [For Docker](#for-docker) + - [Is another Distro supported?](#is-another-distro-supported) + - [Enabling Ubuntu layer](#enabling-ubuntu-layer) + - [Accessing the underlying VM](#accessing-the-underlying-vm) + - [The Virtual Machine's IP is not reachable](#the-virtual-machines-ip-is-not-reachable) + - [Enable reachable IP address](#enable-reachable-ip-address) + - [Are Lima overrides supported?](#are-lima-overrides-supported) + +## How does Colima compare to Lima? + +Colima is basically a higher level usage of Lima and utilises Lima to provide Docker, Containerd and/or Kubernetes. + +## Are M1 macs supported? + +Colima supports and works on M1 macs but not rigorously tested as the author do not currently possess an M1 device. + +Feedbacks would be appreciated. + +## Can config file be used instead of cli flags? + +Yes, from v0.4.0, Colima support YAML configuration file. + +### Editing the config + +``` +colima start --edit +``` + +The config file is located at `$HOME/.colima/default/colima.yaml`. + +For other profiles, `$HOME/.colima//colima.yaml` + +### Setting the default config + +``` +colima template +``` + +### Specifying the config editor + +Set the `$EDITOR` environment variable or use the `--editor` flag. + +```sh +colima start --edit --editor code # one-off config +colima template --editor code # default config +``` + +## Docker + +### Can it run alongside Docker for Mac? + +Yes, from version v0.3.0 Colima leverages Docker contexts and can thereby run alongside Docker for Mac. + +Colima makes itself the default Docker context on startup and should work straight away. + +#### Listing Docker contexts + +``` +docker context list +``` + +#### Changing the active Docker context + +``` +docker context use +``` + +### How to customize Docker config e.g. add insecure registries? + +* v0.3.4 or lower + + On first startup, Colima generates Docker daemon.json file at `$HOME/.colima/docker/daemon.json`. + Modify the daemon.json file accordingly and restart Colima. + +* v0.4.0 or newer + + Start Colima with `--edit` flag. + + ```sh + colima start --edit + ``` + + Add the Docker config to the `docker` section. + + ```diff + - docker: {} + + docker: + + insecure-registries: + + - myregistry.com:5000 + + - host.docker.internal:5000 + ``` + + The config file is located at `$HOME/.colima/default/colima.yaml` for the default profile. + +## How does Colima compare to minikube, Kind, K3d? + +### For Kubernetes + +Yes, you can create a Kubernetes cluster with minikube (with Docker driver), Kind or K3d instead of enabling Kubernetes +in Colima. + +Those are better options if you need multiple clusters, or do not need Docker and Kubernetes to share the same images and runtime. + +Colima with Docker runtime is fully compatible with Minikube (with Docker driver), Kind and K3d. + +### For Docker + +Minikube with Docker runtime can expose the cluster's Docker with `minikube docker-env`. But there are some caveats. + +- Kubernetes is not optional, even if you only need Docker. + +- All of minikube's free drivers for macOS fall-short in one of performance, port forwarding or volumes. While port-forwarding and volumes are non-issue for Kubernetes, they can be a deal breaker for Docker-only use. + +## Is another Distro supported? + +Colima uses a lightweight Alpine image with bundled dependencies and user interaction with the VM is expected to be minimal (if any). + +However, Colima optionally provides Ubuntu container as a layer. + +### Enabling Ubuntu layer + +* CLI + ``` + colima start --layer=true + ``` + +* Config + ```diff + - layer: false + + layer: true + ``` + +### Accessing the underlying VM + +When the layer is enabled, the underlying distro is abstracted and both the `ssh` and `ssh-config` commands routes to the layer. + +The underlying VM is still accessible by specifying `--layer=false` to the `ssh` and `ssh-config` commands, or by running `colima` in the Ubuntu session. + +## The Virtual Machine's IP is not reachable + +This is by design. Reachable IP address is not enabled by default because it requires root access. + +### Enable reachable IP address + +**NOTE:** this is only supported on macOS + +* CLI + ``` + colima start --network-address + ``` +* Config + ```diff + network: + - address: false + + address: true + +## Are Lima overrides supported? + +Yes, however this should only be done by advanced users. + +Overriding the image is not supported as Colima's image includes bundled dependencies that would be missing in the user specified image. diff --git a/INSTALL.md b/docs/INSTALL.md similarity index 100% rename from INSTALL.md rename to docs/INSTALL.md diff --git a/environment/container/docker/context.go b/environment/container/docker/context.go index 4149a1468..3dd3a8809 100644 --- a/environment/container/docker/context.go +++ b/environment/container/docker/context.go @@ -9,6 +9,9 @@ import ( // HostSocketFile returns the path to the docker socket on host. func HostSocketFile() string { return filepath.Join(config.Dir(), "docker.sock") } +func LegacyDefaultHostSocketFile() string { + return filepath.Join(filepath.Dir(config.Dir()), "docker.sock") +} func (d dockerRuntime) isContextCreated() bool { command := fmt.Sprintf(`docker context ls -q | grep "^%s$"`, config.Profile().ID) diff --git a/environment/vm/lima/yaml.go b/environment/vm/lima/yaml.go index f987ac0dd..000f1a717 100644 --- a/environment/vm/lima/yaml.go +++ b/environment/vm/lima/yaml.go @@ -204,6 +204,15 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) { HostSocket: docker.HostSocketFile(), Proto: TCP, }) + if config.Profile().ShortName == "default" { + // for backward compatibility, will be removed in future releases + l.PortForwards = append(l.PortForwards, + PortForward{ + GuestSocket: "/var/run/docker.sock", + HostSocket: docker.LegacyDefaultHostSocketFile(), + Proto: TCP, + }) + } } // handle port forwarding to allow listening on 0.0.0.0 From 775c14da41890f3677f63fc867a840c0bf3da7ab Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 10:47:12 +0100 Subject: [PATCH 2/8] docs: update faq --- docs/FAQ.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 15e56017e..3ca6a869b 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -12,6 +12,9 @@ - [Listing Docker contexts](#listing-docker-contexts) - [Changing the active Docker context](#changing-the-active-docker-context) - [How to customize Docker config e.g. add insecure registries?](#how-to-customize-docker-config-eg-add-insecure-registries) + - [Docker plugins are missing (buildx, scan)](#docker-plugins-are-missing-buildx-scan) + - [Installing Buildx](#installing-buildx) + - [Installing Docker Scan](#installing-docker-scan) - [How does Colima compare to minikube, Kind, K3d?](#how-does-colima-compare-to-minikube-kind-k3d) - [For Kubernetes](#for-kubernetes) - [For Docker](#for-docker) @@ -107,7 +110,42 @@ docker context use ``` The config file is located at `$HOME/.colima/default/colima.yaml` for the default profile. - + +### Docker plugins are missing (buildx, scan) + +Both buildx and scan can be installed as Docker plugins + +#### Installing Buildx + +```sh +ARCH=amd64 # change to 'arm64' for m1 +VERSION=v0.8.2 +curl -LO https://github.com/docker/buildx/releases/download/${VERSION}/buildx-${VERSION}.darwin-${ARCH} +mkdir -p ~/.docker/cli-plugins +mv buildx-${VERSION}.darwin-${ARCH} ~/.docker/cli-plugins/docker-buildx +chmod +x ~/.docker/cli-plugins/docker-buildx +docker buildx version # verify installation +``` +#### Installing Docker Scan + +Install Synk CLI + +```sh +brew tap snyk/tap && brew install snyk/tapsnyk +``` + +Install Docker Scan + +```sh +ARCH=amd64 # change to 'arm64' for m1 +VERSION=v0.17.0 +curl -LO https://github.com/docker/scan-cli-plugin/releases/download/${VERSION}/docker-scan_darwin_${ARCH} +mkdir -p ~/.docker/cli-plugins +mv docker-scan_darwin_${ARCH} ~/.docker/cli-plugins/docker-scan +chmod +x ~/.docker/cli-plugins/docker-scan +docker scan --version # verify installation +``` + ## How does Colima compare to minikube, Kind, K3d? ### For Kubernetes From b762c87e696fb43723abf4296344fb487dc155c5 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 11:45:00 +0100 Subject: [PATCH 3/8] docs: fixes in FAQ --- docs/FAQ.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 3ca6a869b..61fdaf932 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -20,7 +20,7 @@ - [For Docker](#for-docker) - [Is another Distro supported?](#is-another-distro-supported) - [Enabling Ubuntu layer](#enabling-ubuntu-layer) - - [Accessing the underlying VM](#accessing-the-underlying-vm) + - [Accessing the underlying Virtual Machine](#accessing-the-underlying-virtual-machine) - [The Virtual Machine's IP is not reachable](#the-virtual-machines-ip-is-not-reachable) - [Enable reachable IP address](#enable-reachable-ip-address) - [Are Lima overrides supported?](#are-lima-overrides-supported) @@ -45,7 +45,7 @@ Yes, from v0.4.0, Colima support YAML configuration file. colima start --edit ``` -The config file is located at `$HOME/.colima/default/colima.yaml`. +For manual edit, the config file is located at `$HOME/.colima/default/colima.yaml`. For other profiles, `$HOME/.colima//colima.yaml` @@ -55,6 +55,8 @@ For other profiles, `$HOME/.colima//colima.yaml` colima template ``` +For manual edit, the template file is located at `$HOME/.colima/_templates/default.yaml`. + ### Specifying the config editor Set the `$EDITOR` environment variable or use the `--editor` flag. @@ -107,9 +109,7 @@ docker context use + insecure-registries: + - myregistry.com:5000 + - host.docker.internal:5000 - ``` - - The config file is located at `$HOME/.colima/default/colima.yaml` for the default profile. + ``` ### Docker plugins are missing (buildx, scan) @@ -131,7 +131,7 @@ docker buildx version # verify installation Install Synk CLI ```sh -brew tap snyk/tap && brew install snyk/tapsnyk +brew install snyk/tap/snyk ``` Install Docker Scan @@ -167,7 +167,8 @@ Minikube with Docker runtime can expose the cluster's Docker with `minikube dock ## Is another Distro supported? -Colima uses a lightweight Alpine image with bundled dependencies and user interaction with the VM is expected to be minimal (if any). +Colima uses a lightweight Alpine image with bundled dependencies. +Therefore, user interaction with the Virtual Machine is expected to be minimal (if any). However, Colima optionally provides Ubuntu container as a layer. @@ -184,11 +185,11 @@ However, Colima optionally provides Ubuntu container as a layer. + layer: true ``` -### Accessing the underlying VM +### Accessing the underlying Virtual Machine -When the layer is enabled, the underlying distro is abstracted and both the `ssh` and `ssh-config` commands routes to the layer. +When the layer is enabled, the underlying Virtual Machine is abstracted and both the `ssh` and `ssh-config` commands routes to the layer. -The underlying VM is still accessible by specifying `--layer=false` to the `ssh` and `ssh-config` commands, or by running `colima` in the Ubuntu session. +The underlying Virtual Machine is still accessible by specifying `--layer=false` to the `ssh` and `ssh-config` commands, or by running `colima` in the SSH session. ## The Virtual Machine's IP is not reachable From 446b0520458d0f43b200b0a1a001b0ae59e00bce Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 11:46:57 +0100 Subject: [PATCH 4/8] core: update ssh config --- cmd/ssh-config.go | 2 +- environment/vm/lima/cmds.go | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cmd/ssh-config.go b/cmd/ssh-config.go index dd90b1159..bbbf7647d 100644 --- a/cmd/ssh-config.go +++ b/cmd/ssh-config.go @@ -33,5 +33,5 @@ func init() { root.Cmd().AddCommand(sshConfigCmd) sshConfigCmd.Flags().StringVarP(&sshConfigCmdArgs.format, "format", "f", "config", "format (config, cmd)") - sshConfigCmd.Flags().BoolVarP(&sshCmdArgs.layer, "layer", "l", true, "config for the Ubuntu layer (if enabled)") + sshConfigCmd.Flags().BoolVarP(&sshConfigCmdArgs.layer, "layer", "l", true, "config for the Ubuntu layer (if enabled)") } diff --git a/environment/vm/lima/cmds.go b/environment/vm/lima/cmds.go index 9746438bf..cd95b3af4 100644 --- a/environment/vm/lima/cmds.go +++ b/environment/vm/lima/cmds.go @@ -84,7 +84,7 @@ func getIPAddress(profileID, interfaceName string) string { return strings.TrimSpace(buf.String()) } -func UbuntuSSHPort(profileID string) (int, error) { +func ubuntuSSHPort(profileID string) (int, error) { var buf bytes.Buffer cmd := cli.Command("limactl", "shell", profileID, "--", "sh", "-c", "echo $"+layerEnvVar) cmd.Stdout = &buf @@ -166,17 +166,24 @@ func ShowSSH(profileID string, layer bool, format string) (string, bool, error) return "", false, fmt.Errorf("error retrieving ssh config: %w", err) } + ip := IPAddress(profileID) var port int if layer { - port, _ = UbuntuSSHPort(profileID) + port, _ = ubuntuSSHPort(profileID) + // if layer is active and public IP is available, use the fixed port + if port > 0 && ip != "127.0.0.1" { + port = 23 + } + } else { + ip = "127.0.0.1" } out := buf.String() switch format { case "config": - out = replaceSSHConfig(out, profileID, port) + out = replaceSSHConfig(out, profileID, ip, port) case "cmd", "args": - out = replaceSSHCmd(out, profileID, port) + out = replaceSSHCmd(out, profileID, ip, port) default: return "", false, fmt.Errorf("unsupported format '%v'", format) } @@ -184,26 +191,31 @@ func ShowSSH(profileID string, layer bool, format string) (string, bool, error) return out, port > 0, nil } -func replaceSSHCmd(cmd string, name string, port int) string { +func replaceSSHCmd(cmd string, name string, ip string, port int) string { var out []string for _, s := range strings.Fields(cmd) { if strings.HasPrefix(s, "ControlPath=") { s = "ControlPath=" + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock")) } - if port > 0 && strings.HasPrefix(s, "Port=") { - s = "Port=" + strconv.Itoa(port) + if port > 0 { + if strings.HasPrefix(s, "Port=") { + s = "Port=" + strconv.Itoa(port) + } + if strings.HasPrefix(s, "Hostname=") { + s = "Hostname=" + ip + } } out = append(out, s) } if out[len(out)-1] == "lima-"+name { - out[len(out)-1] = "127.0.0.1" + out[len(out)-1] = ip } return strings.Join(out, " ") } -func replaceSSHConfig(conf string, name string, port int) string { +func replaceSSHConfig(conf string, name string, ip string, port int) string { var out bytes.Buffer scanner := bufio.NewScanner(strings.NewReader(conf)) for scanner.Scan() { @@ -215,10 +227,14 @@ func replaceSSHConfig(conf string, name string, port int) string { pad := line[:strings.Index(line, "C")] line = pad + "ControlPath " + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock")) + case port > 0 && strings.HasPrefix(strings.TrimSpace(line), "Hostname "): + pad := line[:strings.Index(line, "H")] + line = pad + "Hostname " + ip + case strings.HasPrefix(line, "Host "): line = "Host " + name - case port > 0 && strings.HasPrefix(line, "Port "): + case port > 0 && strings.HasPrefix(strings.TrimSpace(line), "Port "): pad := line[:strings.Index(line, "P")] line = pad + "Port " + strconv.Itoa(port) } From 6d7c94e4cc3e1ac8be31ef8a2fd77b6048823028 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 12:22:58 +0100 Subject: [PATCH 5/8] core: fix ssh controlpath edge case --- environment/vm/lima/cmds.go | 41 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/environment/vm/lima/cmds.go b/environment/vm/lima/cmds.go index cd95b3af4..58b6bbe1f 100644 --- a/environment/vm/lima/cmds.go +++ b/environment/vm/lima/cmds.go @@ -195,10 +195,10 @@ func replaceSSHCmd(cmd string, name string, ip string, port int) string { var out []string for _, s := range strings.Fields(cmd) { - if strings.HasPrefix(s, "ControlPath=") { - s = "ControlPath=" + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock")) - } if port > 0 { + if strings.HasPrefix(s, "ControlPath=") { + s = "ControlPath=" + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock")) + } if strings.HasPrefix(s, "Port=") { s = "Port=" + strconv.Itoa(port) } @@ -206,6 +206,7 @@ func replaceSSHCmd(cmd string, name string, ip string, port int) string { s = "Hostname=" + ip } } + out = append(out, s) } @@ -218,25 +219,33 @@ func replaceSSHCmd(cmd string, name string, ip string, port int) string { func replaceSSHConfig(conf string, name string, ip string, port int) string { var out bytes.Buffer scanner := bufio.NewScanner(strings.NewReader(conf)) + + hasPrefix := func(line, s string) (pad string, ok bool) { + if s != "" && strings.HasPrefix(strings.TrimSpace(line), s) { + return line[:strings.Index(line, s[:1])], true + } + return "", false + } + for scanner.Scan() { line := scanner.Text() - switch { - - case strings.HasPrefix(strings.TrimSpace(line), "ControlPath "): - pad := line[:strings.Index(line, "C")] - line = pad + "ControlPath " + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock")) + if strings.HasPrefix(line, "Host ") { + line = "Host " + name + } - case port > 0 && strings.HasPrefix(strings.TrimSpace(line), "Hostname "): - pad := line[:strings.Index(line, "H")] - line = pad + "Hostname " + ip + if port > 0 { + if pad, ok := hasPrefix(line, "ControlPath "); ok { + line = pad + "ControlPath " + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock")) + } - case strings.HasPrefix(line, "Host "): - line = "Host " + name + if pad, ok := hasPrefix(line, "Hostname "); ok { + line = pad + "Hostname " + ip + } - case port > 0 && strings.HasPrefix(strings.TrimSpace(line), "Port "): - pad := line[:strings.Index(line, "P")] - line = pad + "Port " + strconv.Itoa(port) + if pad, ok := hasPrefix(line, "Port"); ok { + line = pad + "Port " + strconv.Itoa(port) + } } _, _ = fmt.Fprintln(&out, line) From 2d854007428e83d1bfe5fe788488cd30aabe0acb Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 14:22:04 +0100 Subject: [PATCH 6/8] k3s: fix metrics-server --- environment/container/kubernetes/k3s.go | 4 +--- environment/vm/lima/network/daemon/gvproxy/gvproxy.go | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/environment/container/kubernetes/k3s.go b/environment/container/kubernetes/k3s.go index 7d3bd383a..6102ba5ce 100644 --- a/environment/container/kubernetes/k3s.go +++ b/environment/container/kubernetes/k3s.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/abiosoft/colima/environment/vm/lima/network/daemon/vmnet" - "github.com/abiosoft/colima/cli" "github.com/abiosoft/colima/config" "github.com/abiosoft/colima/environment" @@ -123,6 +121,7 @@ func installK3sCluster( args := []string{ "--write-kubeconfig-mode", "644", "--resolv-conf", "/etc/resolv.conf", + "--flannel-iface", "eth0", } if !ingress { @@ -134,7 +133,6 @@ func installK3sCluster( if ipAddress != "127.0.0.1" { args = append(args, "--bind-address", ipAddress) args = append(args, "--advertise-address", ipAddress) - args = append(args, "--flannel-iface", vmnet.NetInterface) } switch containerRuntime { diff --git a/environment/vm/lima/network/daemon/gvproxy/gvproxy.go b/environment/vm/lima/network/daemon/gvproxy/gvproxy.go index bacdc10a4..70da4e762 100644 --- a/environment/vm/lima/network/daemon/gvproxy/gvproxy.go +++ b/environment/vm/lima/network/daemon/gvproxy/gvproxy.go @@ -66,7 +66,6 @@ func (*gvproxyProcess) Start(ctx context.Context) error { } const ( - NetInterface = "eth1" SubProcessEnvVar = "COLIMA_GVPROXY" socketFileName = "gvproxy.sock" From bd98c4a64c7c845ef8f2fc4af6b724351dcfdcd8 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 14:52:20 +0100 Subject: [PATCH 7/8] docs: update faq --- docs/FAQ.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/FAQ.md b/docs/FAQ.md index 61fdaf932..d2bbeed16 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -9,8 +9,12 @@ - [Specifying the config editor](#specifying-the-config-editor) - [Docker](#docker) - [Can it run alongside Docker for Mac?](#can-it-run-alongside-docker-for-mac) + - [Docker socket location](#docker-socket-location) + - [v0.3.4 or older](#v034-or-older) + - [v0.4.0 or newer](#v040-or-newer) - [Listing Docker contexts](#listing-docker-contexts) - [Changing the active Docker context](#changing-the-active-docker-context) + - [Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?](#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running) - [How to customize Docker config e.g. add insecure registries?](#how-to-customize-docker-config-eg-add-insecure-registries) - [Docker plugins are missing (buildx, scan)](#docker-plugins-are-missing-buildx-scan) - [Installing Buildx](#installing-buildx) @@ -74,6 +78,22 @@ Yes, from version v0.3.0 Colima leverages Docker contexts and can thereby run al Colima makes itself the default Docker context on startup and should work straight away. +### Docker socket location + +#### v0.3.4 or older + +Docker socket is located at `$HOME/.colima/docker.sock` + +#### v0.4.0 or newer + +Docker socket is located at `$HOME/.colima/default/docker.sock` + +It can also be retrieved by checking status + +``` +colima status +``` + #### Listing Docker contexts ``` @@ -85,6 +105,27 @@ docker context list ``` docker context use ``` +### Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? + +Colima uses Docker contexts to allow co-existence with other Docker servers and sets itself as the default Docker context on startup. + +However, some applications are not aware of Docker contexts and may lead to the error. + +This can be fixed by any of the following approaches. Ensure the Docker socket path by checking the [socket location](#docker-socket-location). + +1. Setting application specific Docker socket path if supported by the application. e.g. JetBrains IDEs. + +2. Setting the `DOCKER_HOST` environment variable to point to Colima socket. + + ```sh + export DOCKER_HOST="unix://${HOME}/.colima/default/docker.sock" + ``` +3. Linking the Colima socket to the default socket path. **Note** that this may break other Docker servers. + + ```sh + sudo ln -sf /var/run/docker.sock $HOME/.colima/default/docker.sock + ``` + ### How to customize Docker config e.g. add insecure registries? From bdf3f0eebf4f6303b37eed9518459bca39889d38 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sun, 15 May 2022 15:24:28 +0100 Subject: [PATCH 8/8] core: fix 9p regression --- environment/vm/lima/yaml.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/environment/vm/lima/yaml.go b/environment/vm/lima/yaml.go index 000f1a717..1a6132b57 100644 --- a/environment/vm/lima/yaml.go +++ b/environment/vm/lima/yaml.go @@ -65,16 +65,6 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) { l.Env = make(map[string]string) } - // perform mounts in fstab. - // required for 9p (lima >=v0.10.0) - // idempotent for sshfs (lima