This was my first time learning docker and at first, I didn’t know what it was or how it worked. One time I saw a project deployed with docker that I thought me and my partner needed to do for a project. Then realized it was a lot more complicated than we thought and that it was an actual class offered at my school. I finally took this class and will explain my experiences and what I learned.

What is Docker?

Docker is something that is used in programming when it comes to deploying your applications. This was something that would be used by developers in 2013 as the beginning point of its production. “At Docker, we work to make the developers’ lives easier because we’re developers too. From building Docker tools that improve dev workflows, to creating industry standards for containerizing apps. From contributing to open source projects and to being elected to the CNCF Technical Oversight Committee, the people building Docker tech are one of the things that sets us apart from the rest.”-https://www.docker.com/why-docker This explains some more on what Docker is and what it was developed for. These have been used by major companies like Facebook, Google, etc.

Containers

Containers come into a huge play when dockerizing applications become involved. A container is a process that runs in the background that has features to differentiate from other containers. They are efficient enough to run without messing with the other containers that are there. This is all you need when developing your application and wanting to test the product when it comes time. Another thing to add about this is something called images, docker images. These are the starting point if you are just now using docker for the first time. It contains all that you need to run your application. The container is like the instance for the image and you need both to run the application.

My Experience with Docker

So starting out with docker I realized that I needed to dockerize an application that I made before. This wasn’t something that we make from scratch, but what we can build upon. I thought the perfect project that I could use that was simple was the capstone project I did in one of my classes at school. This project used flask and was easy to install everything. It's not anything huge, but when I first started learning to code this one was of the first websites that I built. It’s supposed to be an anime-explore website.

Screenshot of using Flask

This is the simple flask application that I’m using docker to deploy. Actually, docker works well with flask and deploying it quite easily. There are still multiple steps that you have to do in order for it to work.

This is a screenshot of a Dockerfile

This is one of the files that you need which is called a Dockerfile. You can create this once and use it for multiple stacks. It is a text document that contains all the commands a user could call on the command line to assemble an image. I was struggling to find out which is the right code to use for this particular file, but this worked out for me whilst using flask. Expose 5000 is the port that flask runs on. So you want to always run on that port when you run docker. COPY gets your code and copies it into the blank directory. The RUN builds the container. These are great practices to use from the docker’s documentation.

Docker Build Command

The docker build command builds an image from a Dockerfile and a context. The build’s context is the set of files at a specified location PATH or URL. The PATH is a directory on your local filesystem. The URL is a Git repository location. This is the base that you need to begin building your docker application.

Another thing that you need to do is Docker Compose. Compose is a tool that was created to define and run multiple containers in Docker applications. If you plan to do this then you need a docker-compose.yml file. You will need this file to configure your application for the services.

Screenshot of my docker-compose.yml file

As you can see it's using build. to make the project run whenever you run the docker-compose up command. The ports are not always going to be the same, but since I’m using flask we are going to be using port 5000:5000. Redis is the image that I’m using for this container. After you get it running and want to stop it all you have to do is Ctrl C in your terminal to close it. You will need to do this if you want to run different containers and such.

Conclusion

If you want to deploy your dockerize application then you can do so by using CapRover which is a very easy to use application. It is used for app deployment and web service managers such as Python, MongoDB, etc. It’s really simple to understand from the beginning until you do a deep dive. I’ve had lots of problems trying to deploy my dockerized application that I still have to figure out. If you want to get your server up you’re going to be using DigitalOcean which uses droplets. Droplets are Linux based virtual machines that run on top of virtual hardware. If you want to attempt this you will need to pay for it, but luckily I was given free credits to use for this activity.

All and all I learned so much from deploying an application with docker and it was fun to gain knowledge about it. This is definitely not something that is simple that you can do fast. There will be errors and things not working like how you wanted, but you will eventually get past that. Most of my time was just trying to get my flask app to even work after dockerizing it. Then more issues popped whilst trying to deploy to CapRover. Don’t be afraid to venture out and try new ways to deploy your applications.

References that were used