Exploring Docker
By: Tyler Holland
Tags: Deploy, Docker, Namecheap, Digitalocean, Caprover

What is Docker?

Docker is a DevOps tool that allows people of all computer backgrounds(Mac, Windows, Linux, etc…) to collaborate on the same project without any environmental errors. It is fast and easy to implement. Once the environment is set up, then all it takes to be in the same environment is to run a simple line of code that the author creates.

How to start

The first goal that needs to be accomplished when first getting into docker is to obtain a personal domain from several different websites(I used Namecheap).

Once this goal is complete then it needs to be configured properly. I used Github pages to configure my settings properly to have it up online with some simple text rendered. In order for this step to be made correctly, it is crucial that the DNS settings are set up properly and the one thing that took me a while to figure out was to set the hostname to “@” and have it set to “A record”, otherwise it will not configure properly and the next step will not work. The next thing that needs to be completed is to enforce HTTPS which will better secure the website that was just created, but the only way for HTTPS to be enforced is to have the proper DNS configuration, which is why it is so crucial for it to be configured in the right way. After these steps are completed then a simple and rendered website should be displayed when the site is searched for.

Where to go once this is complete

After the site is configured properly and it is accessible to anyone, then the next thing that needs to be completed is to start learning about Docker itself. Docker needs to be downloaded from Docker and if you do not already have an account, make one and follow the steps to create one.

Docker download page

Once that has had some time to download, it is good to go look for some resources that show how to write a DockerFile. The DockerFile is simple to use, but complex in magnitude and capabilities. The main commands that are needed in order to successfully run a DockerFile are one FROM command, one or two RUN commands, and one CMD command. A full list of all of the possible commands can be found in the Docker documentation.

Docker documentation page

The FROM command will pull the selected base image to build containers off of. This is the first command run in order for the DockerFile to be valid. The next command that is run is the RUN command. This command runs the arguments of the current image that was pulled by the FROM command. This command is written in executables to make it easier to avoid shell string munging. The CMD command is to only have one reference in a DockerFile and if there is more than one CMD then the file will only run the last CMD command. CMD does not build anything onto the image, it just executes the commands that RUN is executing. Once all of those commands are properly executed, then a simple functioning DockerFile can be run.

The DockerFile is set up but how do I run it?

The way I learned to run is to exit from the text editor where the DockerFile is running and to open up a terminal. This is where a few lines of code can be executed to actually build the container. This first line that should be run is:

$ docker build -t USERNAME/IMAGE_NAME .

This will build the DockerFile within the current path then a second line of code should be run in the terminal.

$ docker run --rm --name CONTAINER_NAME IMAGE_NAME

This line will run the IMAGE_NAME image and delete the current container that it is in once the CMD command is run. After these two lines of code are run, then your DockerFile should be accessible to anyone who runs the file.

What’s next?

Once these few steps have been routined in your DockerFile skills then the fun start to be explored with some Docker knowledge. It’s a great practice to go onto an open code based platform to search what other peoples DockerFile looks like and to see what other people have been able to do. The best ones to look for, are those that are easily understandable and to be able to search questions that are thought up while reading through the code.

Now that you have more Docker knowledge

One good source to actually test your Docker skills is to set up your very own server! This can be achieved through many different platforms, but the one I used was DigitalOcean. Here you can set up your own server to have it set up with the “nameofyourproject.domainname” With using DigitalOcean it is good to also install CapRover in order to set up your server and point it to your DigitalOcean server. It only takes a couple of lines to install CapRover.

$ npm install -g caprover

$ caprover serversetup

These two lines will install CapRover onto your machine and set up your server. Then to actually deploy your new app through CapRover, all you need to do is go to the Apps tab then type in your app name and click “Create New App” then deploy your application.

Applying CapRover to your project

After you have set up your server, then it is a good time to set up your own repository with CapRover. For learning purposes, you can use a template that already has CapRover fully implemented to better understand how it is working by looking over the template. A key feature that you want to pay attention to when looking over a template, is to look for a ‘captain-definition’ file. This file tells CapRover how to deploy your application. Next, you should go to CapRover and create a new App and call it what you named your repository. Once you do that, you should go to your configurations settings and link your database. After your database is linked, go back to your project and make sure all of your changes have been committed and run the command:

$ caprover deploy --default

You are going to want to choose the first option then choose the project that you are currently working on. Then run the command:

$ sshroot@<ip_address>

Once inside run:

docker exec -it $(docker ps --filter name=srv-captain--myappname -q) /bin/sh

Next, you are going to want to enable HTTPS in your settings. After these steps are complete, you should have a deployed application that can be seen by anyone who searches for it.