Why you have to follow your dreams

What does it mean to follow your dreams? Do what you like and what you want in life. Many parents give such advice to their kids, and it is true. In this life, you can be what you want from many…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Replace docker desktop on macOS with Vagrant and Virtual Box

I have used Docker since version 0.5.x back when Docker for desktop did not exist. Despite that, we managed to use docker on our Dev machine very well. That’s why I think it’s quite possible to remake a Dev environment without docker desktop.

There are several ways to do this desktop Docker switch. I have added here the link of a very well-done article that inspired me a lot:

The scripts here have been tested on macOS Big Sur 11.6, Vagrant 2.2.16, Virtual Box 6.1, Docker 20.10.10 and Brew 3.3.4

To work, the docker engine can only be launched on a Linux machine. To be able to do this on a MacBook we use a virtual machine (VM).

What we want to do

To make Docker work, we need a Linux VM. To ease the process of creating and handling a Linux VM, we will use Vagrant, which is doing it out of the box by using infra-as-code configuration.

After this script, you should have all the requirements to launch the VM.

By running vagrant up on the same folder of this file, Vagrant will download the box (ubuntu 20.04), configure the VM network, configure VM resources (CPUs, memory, disk size) and will mount the /Users folder into the VM.

After the initial configuration of the VM and when the machine is ready, vagrant will call the provison.sh file (line 29). This file is written for ubuntu 20.04 and will do the initial provisioning of the VM.

Step 2: configure docker-ce to listen on the TCP port 2375.

The step 3 is optional; it allows for the addition of certificates of a potential enterprise docker repository.

Step 4 is also optional; it enables you to start a portainer image, which is an excellent tool for people who would need a GUI.

With these 2 scripts and a vagrant up, you should have a VM up and running, containing docker-ce ready to receive calls on port 2375.

The last thing to do is to set up your machine to redirect docker calls to the VM.

After this script, you will be able to run any docker or docker-compose command from your mac, and these commands will be sent to your local VM.

This solution enables you to have a VM ready to use. This is a good first point, but the problem is that each developer should maintain it up to date. A solution would be that instead of doing the provisioning of the VM via a script at initialisation, we could provision the VM with puppet/chief/ansible and deploy a configuration server so that all VMs are automatically updated.

This error is linked to a previous docker configuration. To correct this error:

The mounting system of virtual box is not perfect. By default, when mounting a folder, the synced folder in the VM is linked to the user vagrant:vagrant uid: 1000, gid: 1000.

Some images need to be run with a very specific user and check the permission of the file system like postgres:12.5 very closely.

Because the filesystem is linked to vagrant, this image will not start.

A workaround (and a good practice) is to use internal volumes instead of linking them to the host machine:

Add a comment

Related posts:

From wild season to clever season

Chances are that by the time you are reading this text you are either recovering from another frantic holiday season or still battling through the grind. Black Friday, Cyber Monday (or any other…

ISLAND QUITTING

Maybe quitting for me is an option, quitting when things go wrong when results are not good as you wanted. Living in the island made me reliaze plenty of things, like me being so stagnant, me being…

Mon Repos apre ai visitatori

Mon Repos apre ai visitatori, il palazzo della famiglia reale greca si mostra in tutta la sua bellezza. Situato sulla costa orientale dell’isola di Corfù vanta una vista meravigliosa. È utilizzato…