Colima - Drop In replacement for Docker Desktop for Mac and Linux

Colima (Container on Linux Machines) is an open source alternative and drop in replacement for Docker Desktop on Mac and Linux.

https://github.com/abiosoft/colima

It is simple to setup and run containers without the need for sudo or root access.

Images can be pulled form both Docker hub (https://hub.docker.com) or Amazon's public registry (https://gallery.ecr.aws)

Amazon's registry is more permissive or friendly with pull rates for both clients and non-clients of AWS.

This article show the setup and basics of running containers on mac. Installation command for Linux can vary based on the distribution type, hence please refer to official documentation for up-to-date steps at 

https://github.com/abiosoft/colima/blob/main/docs/INSTALL.md

Installation on mac:

brew install docker 

brew install docker-buildx

brew install docker-compose

brew install jq

brew install colima

Setup docker compose as docker plugin

mkdir -p $HOME/.docker/cli-plugins

ln -sfn $(which docker-compose) $HOME/.docker/cli-plugins/docker-compose

docker compose version

Start colima in foreground

with default options

colima start -f --network-address

with explicit options 4 cpus 8 GB RAM and 80GB disk space

colima start -f --network-address --cpu 4 --memory 8 --disk 80

Additional environment variables for Test Containers

To make colima work with projects using test containers, we need to add the following environment variables to $HOME/.zprofile or $HOME/.bash_profile

Please refer to this link for more info
 
export TESTCONTAINERS_HOST_OVERRIDE=$(colima ls -j | jq -r '.address')
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export DOCKER_HOST=unix://$HOME/.colima/default/docker.sock

Run postgresql container

docker run -it --rm --name postgres_latest_local -e POSTGRES_DB=mypostgresdb -e POSTGRES_USER=mypostgresuser -e POSTGRES_PASSWORD=mypostgrespassword -p 5432:5432 public.ecr.aws/docker/library/postgres:latest

Connect using any database client with values:

url=jdbc:postgresql://localhost:5432/mypostgresdb
username=mypostgresuser
password=mypostgrespassword
java.jdbc.driver.class.name=org.postgresql.Driver

Run a container with volume mount

Volume mount works only for directory under the user's home directory

docker run -it --rm -v $HOME:/user_home -w /user_home --entrypoint=/bin/bash public.ecr.aws/ubuntu/ubuntu:latest

Start colima in background

colima start --network-address

Check colima status

colima status

List colima instances (profile, cpu, memory, disk space)

colima list

SSH into colima virtual machine

colima ssh

Stop colima instance running in background

colima stop

Add insecure registries:

Get the location of config file template

colima template --print

Then create/open the file using a text editor like vi, nano, code etc..

vi $(colima template --print)

and add/edit the following docker setting

docker:
    insecure-registries:
        - myregistry.example.com:5000
        - internal.docker.example.org:5000

Restart any running instance of colima for changes to take effect

colima stop

colima start --network-address

Upgrade colima

colima stop

colima delete

brew upgrade colima

Fix colima startup issue

Sometimes colima engine might not start due to locks or other corrupted files. The easiest way to fix it is to restart Macbook or Linux machine or clear colima cache with the following command.

rm -rf $HOME/.colima

Comments

Popular posts from this blog

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing