Your Webhosting Questions
Answered by the Webhosting Experts
Tags
...
...

Docker for Beginners: Deploying Containers & the Anatomy of Commands

Hero image of the Docker logo with text reading "Part 3: Docker for Beginners"

Welcome back to our series covering all things Docker. In our previous article, Getting Started with Docker: Installation & Basics, we covered key Docker components including storage and networking as well as the basics of installing Docker onto your Linux system. 

But now that you have Docker installed, what can you do with it? 

In this article we’ll cover the basics of container deployment alongside a step-by-step example deployment using Ghost. In addition, we’ll break down the anatomy of a Docker command, highlighting what each component designates.

To start, let’s deploy our first container with Docker.

Learning the Basics of Docker with Ghost 

Deploying containers with Docker is very quick, and it’s possible to spin-up an entire website with just a single command. To learn the basics, let’s spin-up a simple blog website as a test. 

Ghost is an alternative to WordPress that deploys easily with Docker. That’s not to say that WordPress won’t work with Docker, but because WP’s image size is larger, it’ll mean a longer download time, and for the purposes of our experiment, it’s not the particular service we use that matters, just the container we’re going to be putting it in. 

To deploy Ghost with Docker, run the following command:

docker run -d --name ghost-test -e NODE_ENV=development -e url=http://localhost:3001 -p 3001:2368 ghost

With the command properly entered, Docker will then proceed to download the Docker image for Ghost on Docker hub, extract the image, then build the container and run it. In this particular example, I am using Docker within a VM on a private subnet, with a private IP of 10.0.9.2.

Now, by visiting the server IP on port 3001, we see Ghost is building the site:

Screenshot stating "We'll be right back. We're busy updating our site"

After a minute or so, refreshing that page will present us with a blog website!

Screenshot of Ghost site with Coming Soon messaging

Now what exactly happened here? During this process Docker installed all of the necessary dependencies, spun up a webserver, and exposed the necessary ports to have a live website. 

Pretty cool, right? We just deployed an entire website with a single command. But how is this possible? 

The Anatomy of Docker Commands

Let’s take a look at the command we ran above:

docker run -d --name ghost-test -e NODE_ENV=development -e url=http://localhost:3001 -p 3001:2368 ghost

This is a command that deploys a Docker container according to specified environment variables and options. But let’s take a deeper look at what each piece of this command is designating. 

  • docker run – The command used to deploy single-stack Docker containers. As a matter of fact, this command is seldom used for production deployments as Docker-Compose is preferred. More on that in our next article, Docker Advanced: Deploying with Docker-Compose.
  • -d – This option stands for detached. What it does is leave the container running in the background so our terminal is still usable. 
  • --name – This states the name of the container. This might seem like a trivial option, but container names are also the value for container hostnames! This will be relevant when dealing with networking in Docker, specifically reverse-proxies.
  • -e NODE_ENV=development -e url=http://localhost:3001 – The -e flag is used for loading specific environment variables into the container. In this case, the Ghost instance is set to development. Development configurations are usually for testing and lack certain production requirements, such as a separate database or SSL. The url variable states that the site’s address is localhost, so you would visit this Ghost site via the IP of the server. 
  • ghost – The last value we have, which is the image we want to deploy. This value is also required, so we don’t need a flag for it. 

Looking for a full breakdown of Docker syntax? The best place for finding proper syntax for Docker commands is the official Docker CLI reference.

Understanding Docker-Compose

Now that we know how to deploy a service into a container and understand the anatomy of a basic Docker command, it’s time to look at one of the more advanced elements of the Docker platform, Docker-Compose. By simplifying and unifying your entire Docker deployment into a single, editable file, Docker-Compose allows for more easily reproducible containers and reduced manual input.

In our next article in this series, Docker Advanced: Deploying with Docker-Compose, we’ll cover the basics of Docker-Compose by recreating our Ghost test container from this article, and analyze the ways in which Docker-Compose can help speed up and regulate your container deployments. Read on to learn more or check out our blog and knowledge base for more great content and industry insights from the hosting experts at Hivelocity.

– written by Eric Lewellen

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: [email protected]. We are also available to you through our phone and live chat system 24/7/365.

Tags +
...