Dock Your Code With Docker

Alwan Harrits
5 min readMay 2, 2021

Docker is not a whale carrying tons of containers. It is a platform that helps you in deploying and releasing your applications to the world. Let’s dive right in and see what this blue whale has to offer.

Docker ?

Docker is a platform that you could utilize to basically wrap all the ingredients needed to run an application in one neat little package called container and that allows you to run your application without having to worry whether your local system has the required dependencies or not. Each docker container will contain an image, which is basically a file that is ran in the container. To be exact, a container is a standard unit of software that packages up the code and all it dependencies, while an Image is an executable package that includes everything that is needed to run the application that you want.

Some of you might be thinking, “Well what’s the difference between docker container and virtual machines?”, and to answer that, a container virtualize an operating system so that your application can utilize it, while a virtual machine is a virtualized hardware that could host several different operating systems depending on what you need.

There is also a term called Container Orchestration. Orchestration is an automation of managing containers. The orchestration tool — for example, Docker Compose — will be maintaining the lifecycle of a container according to the settings and configurations that the user have already made. In the mentioned example Docker Compose, it could be used to run multiple different containers at once in one application.

How To Run A Docker Container/Image ?

There are several steps that you need to do before you can get a docker container to start running. Let me walk you through it :
1. Pull the image that you wish to run with the Docker Pull command

Say i want to pull a python image, well all i need to do is do “docker pull python” as you can see from the screenshot. If you don’t know the name of the image you want to get, or even if you don’t know what image you want to get, you could search for it online since there should be tons of resources for it — for example, dockerhub has tons of images you can use.

2. After pulling the image, all you have to do is run the command “docker run [imageName]” and you’re good to go !

How We Use It

For my team’s PPL project, we use a thing called docker-compose.yml. To put it simply, it lets us run several different container at once. Here’s a screenshot of the .yml :

Now there are several parts inside this file, but let’s focus on services. In services, there are 2 different containers — db and web. As you can see, the db service uses the postgres:13-alpine image that is already available somewhere on the internet. You may be wondering, well what image does the web service uses ? The answer is, a custom one. Surprise, surprise, you can actually make a custom image, you can do this by making a file called dockerfile, when the build command is called, it will automatically search for the dockerfile. Here’s an example of the dockerfile that my team uses for our project :

The dockerfile will run different commands that needs to be run to actually create the image. So basically, the dockerfile will become the image.

Now why do we need custom image, you might be asking. Sometimes — or often times — an image that has been provided to us is simply not enough, more often than not we need to customize the image to actually suits our needs. For example in this case, yes we use the python image as a base image, but on top of that we needed to add more dependencies and requirements that we have, set several variables that are needed for the project, etc.

Now, the way we actually start this whole process is by running this command :

And if we want to stop it, simply run this command :

Conclusion

Docker is quite a useful tool to have. Personally, i’ve only ever use docker twice in my life — one for this project, and one for a small assignment on another course — but i can imagine docker being useful for bigger projects. It is a useful tool to have if we don’t know whether or not the environment which we will deploy our server to is actually capable of running our applications. Overall, docker is a tool which could help a team immensely and could prevent any unwanted error when deploying to an environment.

That’s it for this small little article about Docker. My apologies if there are any mistakes. Thank you for reading this article to the end.

References :

  1. https://www.freecodecamp.org/news/docker-simplified-96639a35ff36/
  2. http://docs.docker.com/get-started/overview/#:~:text=Docker%20uses%20a%20client-server,and%20distributing%20your%20Docker%20containers.&text=The%20Docker%20client%20and%20daemon%20communicate%20using%20a%20REST%20API,sockets%20or%20a%20network%20interface.

--

--