Skip to content

Docker Basics

Installing Docker & Kubernetes

Step 1 – Install Homebrew

If you don’t have Homebrew installed, it’s worth doing that first. It’s a great package manager for the Mac. For full details head over to Homebrew Site, buts its as simple using the following command

Step 2 – Install Virtual Box

As we are installing on an Arm64 M1 Mac we cannot use Hombrew at the moment. Instead head to Virtual Box and download the developer preview for macOS. Once downloaded run the installer to add Virutal Box to your system

Step 3 – Install Docker

No we can install Docker for the Mac. Again this is as simple as heading to the Docker website and downloading the Mac version of Docker Desktop.

At this points its also worth creating an account in Docker Hub as you will be using this to download Images and push newly created images to its repo.

Docker Desktop Running on a M1 Macbook Pro

Step 4 – Install Kubernetes

As the ultimate goal of this tutorial is to run our docker images on a simple ( but functional ) Kubernetes Cluster on our Mac, lets also install Kubernetes too

  1. Install kubectl – a command line tool for communicating with a Kubernetes cluster’s control plane, using the Kubernetes API.
    1. brew install kubectl
  2. Install minikube – a local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.
    1. curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-arm64
    2. sudo install minikube-darwin-arm64 /usr/local/bin/minikube

Start Kubernetes

Check its running

Stop Kubernetes

We don’t need K8 running for now, we’ll use it later in the tutorial once we are comfortable running Docker

Learning Docker

There is an excellent tutorial on the Docker website to follow which takes you through all the key elements of running and using Docker containers. This section is my run-through of that tutorial highlighting any differences when running in Mac Arm hardware. This is typically important when building images to upload to the repo as you are building on Arm64, but likely to be deploying to Intel X86 and this needs you to use the BuildX framework.

Head over to Getting Started and read through the foundation info to understand what a container and image is

Getting Started

First we are going to use the getting-started image to create our first container. The command for this is

If you have not use this image before, it will pull all the required dependencies. Once downloaded it will create a new container using this image. By default, Docker assigns a 2-word name to each container made up of 2 random works separated by a hyphen. We can see the container and ensure it is running by opening Docker Desktop

Docker Desktop running on MacBook Pro

Here we can see that the getting-started Container is called ‘eager_meninsky’ and its status is running. We can also go straight to the container by clicking on the link 80:80 or using the URL http://localhost/ in any browser. This opens the web page running on the web server running on the newly created container

We can also use the command line to check if the container is running. We use the ‘docker ps’ command for this as follows

This shows some useful information, specifically the CONTAINER ID, which in this case is ‘bc51c52a64e3’, The id is useful when using the command line options. So for example we can stop ( and restart ) our container with the ‘docker stop ID’ and ‘docker start ID’ as follows

The rest of the tutorial is typically run by following the pages on the website. The tutorial walks you through

  • Creating application ( a simple node.js web app )
  • Update the app and rebuild the image
  • Sharing an image on Docker Hub
    • At this point when running Docker on a M1 Arm64 Macbook Pro we have a conflict on hardware. Docker Hub and Docker playground expect an Intel x86 based image but by default our Docker builds Arm64 images.
    • There is an excellent article on Medium on how to build multiple hardware versions, which boils down to the following steps
      • Step 1
        • We will need to create a “builder”. I will call it mybuilder.
        • docker buildx create –name mybuilder
      • Step 2
        • Then we tell buildx to use mybuilder.
        • docker buildx use mybuilder
      • Step 3
        • We can inspect mybuilder just to be sure.
        • docker buildx inspect –bootstrap
        • As we can see, linux/arm64 and linux/amd64 are both listed (image by author).
      • Step 4
        • Build the image (assuming you are in the directory where your Dockerfile is).
        • docker buildx build –tag [image-tag] -o type=image –platform=linux/arm64,linux/amd64 .
      • Step 5 ( Alternate )
        • We can also build and push to the Docker Hub directly (assuming already logged in to Docker).
        • docker buildx build –push –tag [docker-hubid/image-tag] –platform=linux/arm64,linux/amd64 .

Docker Commands

The following list is not ALL Docker commands, just the ones that I use the most frequently or are the most important to know