
Setting up a macOS environment
If you are running macOS, the quickest way to get Docker up and running is to install Docker for Mac, which you can read more about at https://docs.docker.com/docker-for-mac/install/ and download from https://store.docker.com/editions/community/docker-ce-desktop-mac. Under the hood, Docker for Mac leverages the native macOS hypervisor framework, creating a Linux virtual machine to run the Docker Engine and installing a Docker client in your local macOS environment.
You will first need to create a free Docker Hub account in order to proceed, and once you have completed registration and logged in, click the Get Docker button to download the latest version of Docker:
Once you have completed the download, open the download file, drag the Docker icon to the Applications folder, and then run Docker:

Proceed through the Docker installation wizard and once complete, you should see a Docker icon on your macOS toolbar:

If you click on this icon and select Preferences, a Docker Preferences dialog will be displayed, which allows you to configure various Docker settings. One setting you may want to immediately change is the memory allocated to the Docker Engine, which in my case I have increased from the default of 2 GB to 8 GB:

At this point, you should be able to start up a Terminal and run the docker info command:
> docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.06.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
...
...
You can also start a new container using the docker run command:
> docker run -it alpine echo "Hello World"
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete
Digest: sha256:e1871801d30885a610511c867de0d6baca7ed4e6a2573d506bbec7fd3b03873f
Status: Downloaded newer image for alpine:latest
Hello World
> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
a251bd2c53dd alpine "echo 'Hello World'" 3 seconds ago Exited (0) 2 seconds ago
> docker rm a251bd2c53dd
a251bd2c53dd
In the preceding example, you must run the alpine image, which is based on the lightweight Alpine Linux distribution, and run the echo "Hello World" command. The -it flags specify that you need to run the container in an interactive terminal environment, which allows you to see standard output and also interact with the container via a console.
Once the container exits, you can use the docker ps command to show running containers, and append the -a flag to show both running and stopped containers. Finally, you can use the docker rm command to remove a stopped container.