Docker learning journal

I started to learn Docker through an online tutorial. This post is meant to recording general ideas of what Docker is, why/when I use it, and how it looks like for myself.

What is Docker?

Docker is a tool that packages software in containers. Each Docker container is:

a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. 

https://www.docker.com/resources/what-container

When should I use Docker?

I found Docker useful in the following cases.

  1. When I want to quickly run an application without installing dependencies or setting the environment. To run an application without Docker, I typically have to install all the dependencies and set up the environment (database, server software such as Nginx, etc). For example, to run Java applications on Windows, I’ll have to install JDK and set the PATH variables. Likewise, I won’t have to worry about dependency conflicts. (e.g, If you have to run a PHP application that was made with PHP 5 on a machine which has PHP7. You can’t downgrade the PHP version of the machine because you’re running another PHP application which needs PHP 7.)
  2. When I want to distribute applications onto multiple machines with different OS and/or configurations. Applications can run on a VM installed on a different OS, but a VM is much larger (and uses more memories) than a Docker container.
  3. When I want to move an application from one server to another. Here’s an example scenario. I’ve been host an application on a conventional hosting service (whether it’s a shared server or VPS), and one day I decide to sell it to someone. Now the application is tied to the server, in the sense that the application needs a lot of dependencies in the server and I don’t remember what I installed. Also, its data has to be picked up from its DB. I’m running other applications on the same server, so I can’t give up the whole server lease contract. With Docker, I can take the website and build an image of it. Then, the website can be duplicated from the image, run on another server, and sold it to the person.
  4. When I run microservices with different technologies. For example, I can create a service for concurrency tasks in Go and create a messaging service with Node.js, and so on.

How does Docker look like?

Here’s an image from the official documentation.

How do I host an application with Docker? Can I use Docker on a shared server?

Some server hosting companies (such as A2 hosting) offer Docker hosting services, but it seems that those services are far more expensive than a conventional VPS hosting.

For example, in the case of A2 hosting:

Compare it with their VPS service.

Regarding shared servers:

Q: Is it possible to use docker with a cheap shared hosting account?

A: I would say no because the shared hosting LAMP (server stack) servers also provide a Unix shell, logging in won’t provide the privileges required to start Docker.

https://intellipaat.com/community/38802/is-it-possible-to-use-docker-with-a-cheap-shared-hosting-account

Other candidates are AWS EC2, Google Cloud Platform, Heroku.

Is there any security concern of using Docker?

Read this: https://www.oreilly.com/content/five-security-concerns-when-using-docker/

Compare RUN vs CMD vs ENTRYPOINT

  • RUN lets you execute commands inside of your Docker image.
  • CMD lets you define a default command to run when your container starts (There can only be one CMD instruction in a Dockerfile).
  • ENTRYPOINT allows you to configure a container that will run as an executable.

https://docs.docker.com/engine/reference/builder/

Leave a Reply

Your email address will not be published. Required fields are marked *