Home » DevOps » Docker » Docker Desktop for Mac OS and Windows

About Bhagvan Kommadi

Bhagvan Kommadi is the Founder of Architect Corner & has around 20 years’ experience in the industry, ranging from large scale enterprise development to helping incubate software product start-ups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is member of IFX forum,Oracle JCP and participant in Java Community Process. He founded Quantica Computacao, the first quantum computing startup in India. Markets and Markets have positioned Quantica Computacao in ‘Emerging Companies’ section of Quantum Computing quadrants. Bhagvan has engineered and developed simulators and tools in the area of quantum technology using IBM Q, Microsoft Q# and Google QScript. He has reviewed the Manning book titled : "Machine Learning with TensorFlow”. He is also the author of Packt Publishing book - "Hands-On Data Structures and Algorithms with Go".He is member of IFX forum,Oracle JCP and participant in Java Community Process. He is member of the MIT Technology Review Global Panel.

Docker Desktop for Mac OS and Windows

1. Introduction

In this article, we will explain how to set up Docker Desktop on Mac and Windows. Docker is used for creating apps in the Docker environment with the packages required for building the apps. Docker helps in OS-level virtualization.

2. Docker Desktop

Docker is used in the development and building of applications as a software package to create containers for deployment. Docker Desktop is used in handling changes in code, requirements, operating systems, and cloud environment. It is a lightweight tool to add the libraries, packages, and frameworks required for app execution.

2.1 Prerequisites

Docker Desktop software is required. Apache Tomcat image is obtained from Docker Hub.

2.2 Download

You can download Docker Desktop from this site.

2.3 Setup for Docker

After downloading the installable for Mac or Windows, an installer is run. You can enable the Hyper V windows feature. The Installation process runs till finished. After it is complete, you can close the installation. You can check set up by starting the Docker Desktop tool. You can also use Docker CLI to run the docker.

You can check the docker installation by running the hello-world docker repo which is located at the docker hub.

Docker Hello World
docker run hello-world

The output of the above command will be as below:

Output
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2.4 Docker File Creation

You can create your own Repo and images. Dockerfile details are shown below.

Dockerfile

FROM busybox
CMD echo "Greetings! Docker image is created."

The command to create docker is shown below.

Docker Repo creation

docker build -t bhagvanarch/docker-repo .

The output of the above command will be as below:

Docker Repo creation

Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM busybox
latest: Pulling from library/busybox
76df9210b28c: Pull complete 
Digest: sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209
Status: Downloaded newer image for busybox:latest
 ---> 1c35c4412082
Step 2/2 : CMD echo "Greetings! Docker image is created."
 ---> Running in bc9f0d8ac3d7
Removing intermediate container bc9f0d8ac3d7
 ---> 166dae6f16f8
Successfully built 166dae6f16f8
Successfully tagged bhagvanarch/docker-repo:latest

You can test the docker image created by using the command below:

Docker Testing

docker run bhagvanarch/docker-repo

The output of the above command will be as below:

Docker Testing Output

Greetings! Docker image is created.

You can submit the image to the repo by pushing using the command below:

Docker Repo Push

docker push bhagvanarch/docker-repo

The output of the above command will be as below:

Push Command Output

The push refers to repository [docker.io/bhagvanarch/docker-repo]
1be74353c3d0: Mounted from library/busybox 
latest: digest: sha256:dec937fd6c36b20991e3e51147d3e4553d5d7ec9d0d70627a4f2cd9c48153be5 size: 527

2.5 Docker Web App

Docker solves the issues related to development and operations. It is becoming a popular building software package. Docker helps in creating development, testing, staging, and production environments to handle the changes in the software. Feature testing and functioning are enabled by the Docker Tool.

The base Docker image is created. Multi-stage builds can be modeled as the layers in the docker image. The base image can be extended by having common components and added components. Docker images can be tagged for different versions of releases. Docker images can be enabled for debugging and monitoring.

You can start creating a docker image for a sample web app. The Dockerfile details are provided below:

Dockerfile

FROM tomcat:8.0-alpine

LABEL maintainer="bhagvanarch@gmail.com"

ADD sample.war /usr/local/tomcat/webapps/

EXPOSE 8080

CMD ["catalina.sh", "run"]

You can start creating a web app docker image by using the command below:

Docker build command

docker build -t webapp .

The output of the above command will be as below:

Docker build output

Sending build context to Docker daemon  7.168kB
Step 1/5 : FROM tomcat:8.0-alpine
8.0-alpine: Pulling from library/tomcat
4fe2ade4980c: Pull complete 
6fc58a8d4ae4: Pull complete 
7d9bd64c803b: Pull complete 
a22aedc5ac11: Pull complete 
5bde63ae3587: Pull complete 
69cb0c9b940a: Pull complete 
Digest: sha256:d02a16c0147fcae13d812fa670a4b3c9944f5328b10a5a463ad697d2aa5bb063
Status: Downloaded newer image for tomcat:8.0-alpine
 ---> 624fb61775c3
Step 2/5 : LABEL maintainer="bhagvanarch@gmail.com"
 ---> Running in 25fa21fa57f2
Removing intermediate container 25fa21fa57f2
 ---> a4d46b9470b0
Step 3/5 : ADD sample.war /usr/local/tomcat/webapps/
 ---> 69fe25e523b8
Step 4/5 : EXPOSE 8080
 ---> Running in 5e392e84036b
Removing intermediate container 5e392e84036b
 ---> fd7d13957b79
Step 5/5 : CMD ["catalina.sh", "run"]
 ---> Running in cd3b3f4d3ef0
Removing intermediate container cd3b3f4d3ef0
 ---> db71db63b811
Successfully built db71db63b811
Successfully tagged webapp:latest

You can run the docker based web app by using the command below:

Docker WebApp Run Command

docker run -p 80:8080 webapp

The output of the above command will be as below:

Web app Command Output

05-Jun-2020 18:56:02.032 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.53
05-Jun-2020 18:56:02.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 29 2018 14:42:45 UTC
05-Jun-2020 18:56:02.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.53.0
05-Jun-2020 18:56:02.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
05-Jun-2020 18:56:02.063 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.9.125-linuxkit
05-Jun-2020 18:56:02.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
05-Jun-2020 18:56:02.080 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-1.7-openjdk/jre
05-Jun-2020 18:56:02.081 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.7.0_181-b01
05-Jun-2020 18:56:02.081 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
05-Jun-2020 18:56:02.081 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
05-Jun-2020 18:56:02.081 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
05-Jun-2020 18:56:02.087 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
05-Jun-2020 18:56:02.088 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
05-Jun-2020 18:56:02.088 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
05-Jun-2020 18:56:02.126 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
05-Jun-2020 18:56:02.127 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
05-Jun-2020 18:56:02.127 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
05-Jun-2020 18:56:02.128 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
05-Jun-2020 18:56:02.129 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
05-Jun-2020 18:56:02.130 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.17 using APR version 1.6.3.
05-Jun-2020 18:56:02.134 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
05-Jun-2020 18:56:02.161 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.2o  27 Mar 2018)
05-Jun-2020 18:56:03.279 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
05-Jun-2020 18:56:03.355 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
05-Jun-2020 18:56:03.360 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 5864 ms
05-Jun-2020 18:56:03.899 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
05-Jun-2020 18:56:03.902 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
05-Jun-2020 18:56:04.130 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/sample.war
05-Jun-2020 18:56:09.276 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/sample.war has finished in 5,141 ms
05-Jun-2020 18:56:09.282 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
05-Jun-2020 18:56:09.456 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 174 ms
05-Jun-2020 18:56:09.457 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
05-Jun-2020 18:56:09.531 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 74 ms
05-Jun-2020 18:56:09.533 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
05-Jun-2020 18:56:11.175 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 1,642 ms
05-Jun-2020 18:56:11.177 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
05-Jun-2020 18:56:11.295 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 118 ms
05-Jun-2020 18:56:11.296 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
05-Jun-2020 18:56:11.449 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 152 ms
05-Jun-2020 18:56:11.512 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
05-Jun-2020 18:56:11.571 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
05-Jun-2020 18:56:11.627 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 8267 ms

The tomcat server can be accessed at http://localhost. (port 80 is the default port). The output is shown below:

docker desktop - tomcat landing
Tomcat Landing Page

The sample web app bundled with tomcat can be accessed at http://localhost/sample/. The webpage output is shown in the image below:

docker desktop - hello world
Hello World

3. Download the Source Code

Download
You can download the full source code of this example here: Docker Desktop for Mac OS and Windows

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments