Running containers on a Mac

Docker Desktop can be used for free as part of a Docker Personal subscription for: small companies (fewer than 250 employees AND less than $10 million in annual revenue), personal use, education, and non-commercial open source projects.
  1. Podman
  2. Vagrant with virtual box
brew install podman
podman info
podman machine init
podman machine start
brew install python@3.10pip3 install podman-compose
# Install VirtualBoxbrew install --cask virtualboxbrew install --cask virtualbox-extension-pack# Install Vagrant and the vbguest plugin to manage VirtualBox Guest Additions on the VMbrew install vagrantvagrant plugin install vagrant-vbguest# Install Docker CLIbrew install dockerbrew install docker-compose
mkdir vagrant-docker-engine
cd vagrant-docker-engineecho \"Vagrant.configure('2') do |config|config.vm.box = 'ubuntu/focal64'config.vm.hostname = 'docker.local'config.vm.synced_folder "/Users/irfan/docker_data", "/vagrant", type: "rsync"config.vm.network 'private_network', ip: '192.168.56.4'config.vm.network 'forwarded_port', guest: 2375, host: 2375, id: 'dockerd'config.vm.provider 'virtualbox' do |vb|vb.name = 'ubuntu-docker'vb.memory = '2048'vb.cpus = '2'endconfig.vm.provision 'shell', path: 'provision.sh'# Configuration for Port Forwarding# Uncomment or add new ones here as required#config.vm.network 'forwarded_port', guest: 6379, host: 6379, id: 'redis-server'#config.vm.network 'forwarded_port', guest: 5432, host: 5432, id: 'postgres-server'#config.vm.network 'forwarded_port', guest: 3306, host: 3306, id: 'mysql-server'end" | tee Vagrantfile > /dev/nullecho \"# Install Dockerapt-get remove docker docker-engine docker.io containerd runcapt-get updateapt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release net-tools software-properties-commoncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgecho 'deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable' | tee /etc/apt/sources.list.d/docker.list > /dev/nullapt-get updateapt-get install -y docker-ce docker-ce-cli containerd.io# Configure Docker to listen on a TCP socketmkdir /etc/systemd/system/docker.service.decho \\'[Service]ExecStart=ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock' | tee /etc/systemd/system/docker.service.d/docker.conf > /dev/nullecho \\'{\"hosts\": [\"fd://\", \"tcp://0.0.0.0:2375\"]}' | tee /etc/docker/daemon.json > /dev/nullsystemctl daemon-reloadsystemctl restart docker.service" | tee provision.sh > /dev/nullchmod +x provision.sh
config.vm.synced_folder
vagrant up
The IP address configured for the host-only network is not within the
allowed ranges. Please update the address used to be within the allowed
ranges and run the command again. Address: 192.168.56.4
Ranges: 192.168.xx.0/21
# Save IP to a hostname
echo "192.168.66.4 docker.local" | sudo tee -a /etc/hosts > /dev/null

# Tell Docker CLI to talk to the VM
export DOCKER_HOST=tcp://docker.local:2375
# Uncomment or add new ones here as required#config.vm.network 'forwarded_port', guest: 6379, host: 6379, id: 'redis-server'

Vagrant Cheatsheet

vagrant suspend - stop the VM for saving system resources. This does not delete any data. Just run vagrant up to spin up the VM.

  1. Press ⌘ , to open the IDE settings and select Build, Execution, Deployment | Docker.
  2. Click + to add a Docker configuration.
  3. Select TCP socket and specify the Docker API service URL in Engine API URL: tcp://localhost:2375.
  1. If everything is correct, you should see Connection successful at the bottom of the page. Else check if the VM is running or suspended.
  2. Double-click the configured Docker connection in the Services tool window (View | Tool Windows | Services or ⌘ 8).

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Irfan Ali Shaik

Irfan Ali Shaik

Software engineer, technology enthusiast