Tuesday, November 16, 2021

macOS: Docker volumes and Minikube

This morning I decided to replace Docker Desktop on my mac with the Hyperkit + Minikube combo like explained in Run Docker without Docker Desktop on macOS.

Volumes

However, some file mounted through a volume in docker-compose invariably resulted in a directory being created in the container instead of a file.
docker-compose.yaml

version: "3.8"
services:
  postgres:
    container_name: oss-postgres
    image: postgres:14-alpine
    stdin_open: true
    tty: true
    restart: always
    ports:
      - 5432:5432
    volumes:
      - ./postgres/postgres.sh:/docker-entrypoint-initdb.d/postgres.sh
    environment:
      POSTGRES_PASSWORD: "xxx"
logs
oss-postgres  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/postgres.sh
oss-postgres  | /usr/local/bin/docker-entrypoint.sh: line 169: /docker-entrypoint-initdb.d/postgres.sh: Is a directory
oss-postgres exited with code 126
It appears that the volumes need being created in the Minikube VM beforehand (source: Replace Docker Desktop with Minikube and Hyperkit on macOS), like in:
> minikube stop
> minikube start --mount --mount-string="/Users/jerome/src/boss/:/Users/jerome/src/boss/" --memory 4096 --cpus 4

Ports

Any service previously reachable through localhost by port forwarding is now available by using docker.dev, mapped to minikube ip in /etc/hosts. 

NOTE

Never use .local domain on macOS, or DNS resolving will become awfully slow: use for ex. docker.dev instead of docker.local for the hostname of the minikube ip, contrary to what the 1st article proposes.