Docker Desktop: How to Install & Configure on macOS ?

Docker is a set of the platform as service products that use OS-level virtualisation. It allows to deliver software in packages (containers). These containers are isolated from one another. They also bundles software, libraries, and configuration files. They can communicate with each other through well-defined channels. Wikipedia

Step 1 — Installing Docker Desktop

Go to the official docker website and download the last software version, the current latest version that we used for this tutorial is 20.10.6, build 370c289

Step 2 — Drag And Drop The Start The Installation

As any other Mac software installation we need to drag and drop the docker.app into Applications folder:

docker-installation-macos

Step 3 — Launch The Docker Desktop App

Double click on the docker app to start.

docker-engine-starting
listing all running containers

Step 4 — Copy The Command Line and Run into The Terminal

In order to start running the docker image execute on the terminal consol the command bellow:

docker run -d -p 80:80 docker/getting-started
terminal-execute-run-cmd

To check the running containers you can run the command bellow in the terminal:

 docker ps
terminal-execute-ps-cmd

Or also we can look in the docker desktop UI at Containers/Apps tab:

desktop-display-containers

For some security reason in some companies, we need to configure a proxy to access to docker hub to get images. We can do this configuration using the docker desktop ui:

ckeck-resources

Step 5 — Use Of A Dockerfile

The dockerfile is similar to the makefile in gcc jargon. It is a configuration file with a set of commands to build a customised docker image.

As given in the example hereafter:

FROM ubuntu:18.04

RUN apt-get update -y
RUN apt-get install -y python
COPY . /app
CMD python /app/Src/app.py

Each instruction creates one layer:

  • FROM creates a layer from the ubuntu:18.04 Docker image.
  • COPY adds files from your Docker client’s current directory.
  • RUN execute installation command.apt-get install
  • CMD specifies what command to run within the container.

To run an image and generate its container:

docker build -t ubuntu .

docker run -it ubuntu
tools-build

Step 6 — Use Of A Dockerfile-Compose File

The docker-compose is a yaml file containing the composition of your infrastructure. It defines all links between all services need by your app:

  • Python image + postgres image + …

docker-compose.yml looks like this:

version: "3.9"
   
services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

Conclusion

For more information about the Compose file. see to the official docker website.

Compose has commands for managing the whole lifecycle of your application:

  • Start, stop, and rebuild services
  • View the status of running services
  • Stream the log output of running services
  • Run a one-off command on a service
@freecoder
@freecoder

With 15+ years in low-level development, I'm passionate about crafting clean, maintainable code.
I believe in readable coding, rigorous testing, and concise solutions.

Articles: 29