Docker 101/DockerFile on a MacOS Laptop
Tags: docker, programming, tutorial, productivity
Published: 2022-02-24 18:11:37

Welcome to another post about Docker! If you need help with the installation please refer to my other post titled **Docker Installation on a MacOS Laptop**.

#Why Docker is Powerful?
Docker is an open platform application for developing, running, and shipping off applications through containers. Docker is powerful because it takes a larger application and breaks it down into smaller more chuckable pieces aka services. Microservices are a cloud based approach where a single application is made up of different working smaller services. Below is an image that shows some structure. Everyone can communicate in one _single_ place. Each of the services can be considered a microcomputer. Some known companies that are notable which use Docker are Spotify, Yelp, and Uber to name a few.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oe5aj7nyj0htu66h8iha.png)

**How to get Started with Play with Docker**
Go to [Docker Playground](https://labs.play-with-docker.com/ ) to start to play with Docker. After you will be able to start to add a new instance. From there, you are able to access your own server to run Docker. To start to see this come to light, you can start an instance to run an application. A Dockerfile describes how the actual container is built. A snippet that shows this is...
`FROM node:10-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "/app/src/index.js"]
EXPOSE 3000`

To build a container, run `docker build -t todoapp .` Then you can look at images, `docker images` and then run a container `docker run -d -p 3000:3000 todoapp` and multiple ones 
`docker run -d -p 3001:3000 todoapp
docker run -d -p 3002:3000 todoapp
docker run -d -p 3003:3000 todoapp`

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

**Screenshots of the NewsAPI Microservice** 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pehfqzpsv76c3vokzx8.png)
Below shows the success of a web component communicating with a backend microservice and the newsapi.org.

#SUCCESS!

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

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

**How to Create a DockerFile for Repo**

1. Find the GitHub Repo and run it on [Docker Playground](https://labs.play-with-docker.com/)
2. Run `touch Dockerfile`
3. Select the editor to open and see the file.
4. Click on Dockerfile (double click) and enter...

`# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]`

5. Run `docker build -t getting-started .`
6. Run `docker run -dp 3000:3000 getting-started` to start.
7. When open it, should be running locally on the port.

Bonus Feature: Image below shows using `touch` the created **Dockerfile for Nasa Image Search!!!!!**

![Dockerfile- Nasa Image Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b53pwwuoawad2ggd0ga.png)

#CONGRATULATIONS!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1br95mfg4zoz3tuq53f.gif)