DEV Community

jfz5219
jfz5219

Posted on

Why is Docker Powerful and How to Get Started with "Play with Docker"

Why use Docker?

Docker is great tool you should use when developing an application. Many new developers probably start building a monolithic application. This could be when all your services, like your server, database, files are built on top of one operating system in a VM. There may be some downsides to this. For example, if there is an error with one of your services, you might risk of messing up the other services by trying to fix that one issue.

With Docker, you are able to separate these services into containers so we can get rid of the dependencies they might have with each other. By doing this, these services will be self-contained. Now, it can exist by itself with all resources and dependencies encapsulated. Once we have these containers, we can move onto a microservice architecture.

I think of microservices as Lego pieces because of how flexible a Lego structure is. If one piece breaks, you can effortlessly replace it with another. When an application is built on microservices that comes in a form of containers, these containers are like Lego pieces that can be easily replaced. Let's say your server, in a container, is causing errors. This will not effect your container with UI components and you can just make to the container update with a new server (if you decide to).

Docker also works great in a collaborative setting. When another developer needs your application. They will already have the everything set up because Docker will help create the same environment that you worked with onto their working environment. This makes your application very portable.

Another aspect of docker is its ability to automate work. You may have had to change directories, copy files, install dependencies when creating an application. However, all of this coding in your command prompt can be written to a dockerfile.

Play with Docker

Using Play with Docker is a great way to introduce yourself to docker. Follow this tutorial first. It will show you how to create a few different type of containers. Once you are familiar with the concept of containerization, try using "Play with Docker". I used this to do an activity that I will discuss next.

Here is a good video explaining Docker:
https://www.youtube.com/watch?v=eGz9DS-aIeY

NewsAPI Activity

Our class did an activity where we had to retrieve news from a news API and display it on a component. This required the use two containers; a server container and a component container. Each container needed a dockerfile and by using a docker-compose.yml file, we are able to run the multiple dockerfiles.

component dockerfile
Image description

server dockerfile
Image description

docker-compose.yml
Image description

How to Create a DockerFile

By using what I learned from the NewsAPI activity, this is how to create a dockerfile for the NASA image search repo(an assignment on components I did for class).

First, create a file called Dockerfile. Then, we need a base image, I'll be using the same one from the NewsAPI example. This is what I think a dockerfile would look like for my NASA image search repo.

FROM socialengine/nginx-spa

WORKDIR /IST402/nasa-search-image

COPY package.json ./
RUN npm install

COPY . .
CMD["npm", "start"]

Enter fullscreen mode Exit fullscreen mode

I tried following the example from the NewsAPI dockerfile.

Top comments (0)