😁

docker client + colimaで、Docker Desktopを使用しないでdockerを使用する

2023/04/30に公開

colima

https://github.com/abiosoft/colima

install

brew install colima

docker client

install

https://docs.docker.com/engine/install/binaries/#install-client-binaries-on-macos

Setting

colima起動前確認
mac:~ $ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT               ERROR
default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock   
colima 起動
mac:~ $ colima start
INFO[0000] starting colima                              
INFO[0000] runtime: docker                              
INFO[0000] preparing network ...                         context=vm
INFO[0000] creating and starting ...                     context=vm
INFO[0042] provisioning ...                              context=docker
INFO[0042] starting ...                                  context=docker
INFO[0048] done        
colima起動後確認
mac:~ $ docker context ls
NAME       DESCRIPTION                               DOCKER ENDPOINT                                  ERROR
colima *   colima                                    unix:///Users/sora/.colima/default/docker.sock   
default    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                      
実行確認
mac:~ $ docker run hello-world 
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

colima status

mac:~ $ colima status
INFO[0000] colima is running using QEMU                 
INFO[0000] arch: x86_64                                 
INFO[0000] runtime: docker                              
INFO[0000] mountType: sshfs                             
INFO[0000] socket: unix:///Users/sora/.colima/default/docker.sock 
mac:~ $ colima ls    
PROFILE    STATUS     ARCH      CPUS    MEMORY    DISK     RUNTIME    ADDRESS
default    Running    x86_64    2       2GiB      60GiB    docker   

colima stop

colima停止
mac:~ $ colima stop
INFO[0000] stopping colima                              
INFO[0000] stopping ...                                  context=docker
INFO[0001] stopping ...                                  context=vm
INFO[0005] done   

参考

自動で切り替わるので使わないが、切り替える方法

colimaを使うように設定
mac:~ $ docker context use colima
colima
Current context is now "colima"
mac:~ $ docker context ls
NAME       DESCRIPTION                               DOCKER ENDPOINT                                  ERROR
colima *   colima                                    unix:///Users/sora/.colima/default/docker.sock   
default    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                      
mac:~ $ echo $DOCKER_HOST

colima help

mac:~ $ colima --help
Colima provides container runtimes on macOS with minimal setup.

Usage:
  colima [command]

Available Commands:
  completion  Generate completion script
  delete      delete and teardown Colima
  help        Help about any command
  kubernetes  manage Kubernetes cluster
  list        list instances
  nerdctl     run nerdctl (requires containerd runtime)
  restart     restart Colima
  ssh         SSH into the VM
  ssh-config  show SSH connection config
  start       start Colima
  status      show the status of Colima
  stop        stop Colima
  template    edit the template for default configurations
  version     print the version of Colima

Flags:
  -h, --help             help for colima
  -p, --profile string   profile name, for multiple instances (default "default")
  -v, --verbose          enable verbose log
      --version          version for colima
      --very-verbose     enable more verbose log

Use "colima [command] --help" for more information about a command.
mac:~ $ colima start --help
Start Colima with the specified container runtime and optional kubernetes.

Colima can also be configured with a YAML file.
Run 'colima template' to set the default configurations or 'colima start --edit' to customize before startup.

Usage:
  colima start [profile] [flags]

Examples:
  colima start
  colima start --edit
  colima start --runtime containerd
  colima start --kubernetes
  colima start --runtime containerd --kubernetes
  colima start --cpu 4 --memory 8 --disk 100
  colima start --arch aarch64
  colima start --dns 1.1.1.1 --dns 8.8.8.8
  colima start --dns-host example.com=1.2.3.4
  colima start --kubernetes --kubernetes-disable=coredns,servicelb,traefik,local-storage,metrics-server

Flags:
      --activate                     set as active Docker/Kubernetes context on startup (default true)
  -a, --arch string                  architecture (aarch64, x86_64) (default "x86_64")
  -c, --cpu int                      number of CPUs (default 2)
      --cpu-type string              the CPU type, options can be checked with 'qemu-system-x86_64 -cpu help'
  -d, --disk int                     disk size in GiB (default 60)
  -n, --dns ipSlice                  DNS resolvers for the VM (default [])
      --dns-host strings             custom DNS names to provide to resolver
  -e, --edit                         edit the configuration file before starting
      --editor string                editor to use for edit e.g. vim, nano, code (default "$EDITOR" env var)
      --env stringToString           environment variables for the VM (default [])
  -h, --help                         help for start
  -k, --kubernetes                   start with Kubernetes
      --kubernetes-disable strings   components to disable for k3s e.g. traefik,servicelb (default [traefik])
      --kubernetes-version string    must match a k3s version https://github.com/k3s-io/k3s/releases (default "v1.25.4+k3s1")
  -l, --layer                        enable Ubuntu container layer
  -m, --memory int                   memory in GiB (default 2)
  -V, --mount strings                directories to mount, suffix ':w' for writable
      --mount-type string            volume driver for the mount (sshfs, 9p, virtiofs) (default "sshfs")
      --network-address              assign reachable IP address to the VM
      --network-driver string        network driver to use (gvproxy, slirp) (default "gvproxy")
  -r, --runtime string               container runtime (docker, containerd) (default "docker")
  -s, --ssh-agent                    forward SSH agent to the VM
      --ssh-config                   generate SSH config in ~/.ssh/config (default true)
  -t, --vm-type string               virtual machine type (qemu, vz) (default "qemu")

Global Flags:
  -p, --profile string   profile name, for multiple instances (default "default")
  -v, --verbose          enable verbose log
      --very-verbose     enable more verbose log

Discussion