Install Docker On MacOS 10.13 Or Newer (i.e Big Sur, Catalina, Mojave, or High Sierra) And Deploy A NGINX Container.
Docker is basically an application that makes use of OS-level virtualization to make it possible to run isolated applications / software containers. If you are a developer and need a free and easy to use platform for testing and deployment purposes but without using your main software development operating system then Docker is what you need. Docker is also a good platform that allows IT admins to quickly deploy isolated apps and software services. Whats cool is that containers can also be moved from one server to another, updated and even run in large clusters. The aim of this tutorial is to show you how to install Docker on MacOS 10.13 or newer (i.e Big Sur, Catalina, Mojave, or High Sierra) and deploy a NGINX web server container.
In order to complete this tutorial successfully the following items are required. Please ensure to have these items available before taking implimentation action on this tutorial:
1) Authorized access to a Mac mini, Mac Book Pro, iMac or Mac Pro.
2) MacOS 10.13 or newer i.e Big Sur, Catalina, Mojave or High Sierra.
3) The docker installation file for MacOS.
4) Internet access to download and deploy the NGINX web server docker container.
1) Go to the official docker website and download the free / paid version of docker for MacOS
2) Install Docker on MacOS and pull the NGINX image from the docker HUB
3) Run the NGINX container and test the web server using a web browser
4) Learn how to remove docker containers, images and volumes.
Step 1: Download Docker Desktop For MacOS
1)Click HERE to go to the docker download page to get a copy of the docker desktop installation file. The download page will automatically detect the operating system that you are using will give you the appropriate download link for your OS.
If you would like to purchase docker, the Pro version of docker desktop costs $7 per month and docker for teams costs $9 per user per month.
Docker is also available on the AWS(Amazon Web Services) and Microsoft Azure cloud computing platform. Information on how to deploy docker on AWS and AZURE is available HERE.
Step 2: Install Docker And Create The NGINX Container.
2) Open FINDER and go to the folder where the DOCKER DESKTOP .dmg file has been download to. Right click on it and select OPEN. A dialogue box will be displayed notifying you that MacOS is verifying and opening the Docker.dmg file.
3) The next step is to drap the docker application into the APPLICATIONS FORLDER in FINDER. Using your mouse long press on the docker icon and place in on the APPLICATIONS folder shortcut as shown in the image on the right.
Step 3: Open Docker And Create The NGINX Container.
4) Once docker is installed on to your Mac open the APPLICATIONS FOLDER and right click on DOCKER. A warning message will be displayed notifying you that Docker is an application downloaded from the internet and will ask you whether to open it or not.
Click on the OPEN button to proceed.
5) In order for DOCKER to run and function properly it requires priviledged access to MacOS. On the “DOCKER DESKTOP NEEDS PRIVILEDGED ACCESS” message box click on OK and type in your MacOS password on the “DOCKER IS TRYING TO INSTALL A NEW HELPER TOOL” message box.
To check if DOCKER DESKTOP is running click on the DOCKER DESKTOP icon on the menu bar and you should see a greens circle with the words ” DOCKER DESKTOP IS RUNNING”
6) Since the objective of this tutorial is to show you how to create a docker container by setting up a NGINX web server in docker. Open the MacOS terminal application and type the command
You will notice that the output of this command will show that there are no images found.
Next, run the following command to pull the NGINX image from the docker HUB
docker pull nginx
Run the docker images command again and the new NGINX container will be returned as shown in the image on the right
7) To run the NGINX container enter the following command in the MacOS terminal.
docker run – -name billysoft-docker-nginx -p 80:80 nginx
This command will start the NGINX container and below is a brief explanation of the above command.
- – -name gives the container an easy to read name
- -p tells docker the network ports to use for the container
- 80:80 – The first 80 is the external port used when accessing the container from your network and the second 80 is the internal docker port
- nginx is the image that will be used to deploy container.
8) Next, open a new web browser tab and type the IP address of the computer hosting the NGINX docker container. Please note that if you used a different port number you may have to specify it. e.g 192.168.1.1:90.
If the NGINX container is running locally on your computer that jus type localhost or 127.0.0.1 in the web browser address bar.
9) You will notice that if you open the MacOS terminal if you press COMMAND + C the container will be terminated. This is because the container wont be running in detached mode. To run the container in detached mode use the following command instead:
docker run – -name billysoft-docker-nginx -p -d 80:80 nginx
10) Docker containers can also be managed from the docker dashboard. The docker dashboard allows you to perfom tasks such as viewing the status of all containers, viewing the container command line interface and also starting, stopping and deleting containers.
To open the dashboard click on the docker icon on the MacOS menu bar and select the DASHBOARD option.
Step 5: Learn How To Delete A Docker Container.
11) In docker there are many commands that can be used when it comes to removing containers, images and volumes. However we’ll just show you the basic commands that can be used if you would like to remove these items.
To remove all used objects and basically do a docker system clean up run the following command in the MacOS terminal:
docker system prune.
12) To remove a docker container first run the following command to list out all containers. This command will also indicate the CONTAINER ID for each container.
docker container ls -a
Once you identify the container id of the container yyou would like to remove simply run the following command:
docker container -rm CONTAINER_ID
The commands for removing docker images and volumes are as follows :
docker image -rm IMAGE_ID
docker volume -rm VOLUME_NAME