The Power Of Docker
Tags: docker, webdev
Published: 2022-02-28 03:38:49

Initially, I had never heard of Docker or even viewed examples of utilizing it. However, I now understand why Docker is so powerful after playing with it a bit.  

Today I will cover the effectiveness of Docker, getting started with playing with Docker and how to create a Dockerfile. 

---

## What is Docker?
![Image of Docker logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f591eqlmfrlht7wqqeh1.png)
You might be questioning yourself, "what the hell is Docker?" Trust me, I was there too. [Docker](https://docs.docker.com/get-started/overview/) is an open-source platform that lets developers build, ship, and run applications. Docker is powerful because it makes it easier for you to separate your applications from your infrastructure, enabling rapid software delivery. 

## How does it work?
Docker works by providing a standard way to run your code. Docker is an operating system for [containers](https://docs.docker.com/get-started/overview/#containers). Just as virtual machines virtualize (remove the need for direct management) server hardware, containers virtualize the operating systems on servers. Each server has Docker installed and provides simple commands for building, starting, and stopping containers.

## Getting Started
To get started, head over to the [Docker 101 tutorial](https://www.docker.com/play-with-docker#101%20Tutorial/#101%20Tutorial) under tutorial. You can either take the tutorial on your desktop or in the cloud. In this example, I would be taking the tutorial in the cloud found [here](https://labs.play-with-docker.com/).
![Image description of docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h734l5w6ao9f3m6fa8sc.png)


To access their interactive playground, you first need to [create an account](https://hub.docker.com/). If you have an account, simply login in using your Docker ID and password.

Once you log in, you'll see your own Docker VM. To launch Docker's tutorial, you first must create an instance.![Image description of docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxv71xt6kno9he19tsih.png)

Next, in your PWD terminal, write the following command
```
docker run -dp 80:80 docker/getting-started:pwd
```
This would create a container in port 80. 
![Image description of docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/670dddqc63ip18ylo7mc.png)

After successfully running the command, port 80 would display a container containing the Dockers 101 tutorial. Throughout this series, you will learn the commands for Docker while seeing the benefit of why building a microservices infrastructure is better instead of a monolithic one. 
![Image description of docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2mwyoiradcdsdrhg7myc.png)

---

![Image description of tutorial](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bdkofpgu05ohcw41yhkl.png)

Congratulations, you have reached all the necessary steps to start with Docker. Now head on over to the tutorial and learn how to utilize Docker in your applications. 

---

## NASA API
In this sections I would be teaching you how to create a Dockerfile for one of my latest project.  

To run the NASA API project in Docker, we need to ensure our Docker file has the needed scripts. 

1. In Dockers playground, first, clone our repository and `cd` into the folder.
![Example of cloning a repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8ur4w1mpuc0x58c1d36.png)
 
2. Next, we need to create a Docker file. In your PWD type `touch Dockerfile`.
![Image description of docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/94qaxfdtqxsk0h9p2m3z.png)

3. After creating the file, you'll want to open the editor's tab and locate the Dockerfile. 
![Image description of docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmtf5bs19gafzeuiwbvf.png)

4. Our Docker file needs some scripts to run. In the Dockerfile, enter the following command and save the new changes.
``` 
FROM node:12

WORKDIR /home/node/app

COPY package.json ./
RUN yarn install

COPY . .

CMD [ "yarn", "start" ]
```
5. Next, we need to build the container image using the docker build command. `docker build -t nasa-image`
![Image description of pwd](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wzk8186p7rrsa65u56a.png)

Let's run the application now that we have an image! To do so, we will use the `docker run` command.

- `docker run -dp 8000:8000 nasa-image`

- After running the command open your local host with the port 8000. 

At this point, you should have a running Docker application.  

As always, thank you for reading, and I hope you have a wonderful day.