Docker Guide: How, When, and Why the Container Software is Used

Use code KB4KDO0L9 to receive a 10% recurring discount on any server.

First released in 2012, Docker has taken the DevOps world by storm as an innovative platform for deploying new software. But what is Docker, and how does Docker work, and how can you leverage it to improve your DevOps workflow?

In this article, we’ll outline a Docker guide for you so that you can learn more about this software and determine if it’s a good fit for your next project.

See Also:Jenkins Software Tutorial: Why and How the CI Tool is Used

What is Docker?

Docker is a software tool which enables you to create and deploy standalone containers which contain a specific element of a software project. For example, you may deploy an apache container, a MySQL container, and a PureFTP container in order to create a simple web server. Each Docker container receives its own CPU, memory, block I/O, and network resources in order to segment the server between applications.


Components of Docker

Dockerfiles: A text file which contains the commands needed to create a docker image. The docker build command is used to build a docker container using the commands in the dockerfile.

Docker Image: The image used to create a docker container. This is pulled from the Docker repository.

Docker Repository: The central database which stores the dockerfiles used to generate the docker image, and in turn create the docker container.

Docker Container: Similar to a virtual machine, the Docker container is the isolated environment running on the server which contains the software outlined in the dockerfile. It has its own CPU, memory, block I/O, and network resources in order to segment the server between applications.

Docker Swarm: A cluster of servers that are connected together.

How Much Does Docker Cost?

Docker Engine Community is available for free and is suitable for most personal applications and small business use. Docker recommends upgrading to the enterprise edition for production use in a large enterprise. The enterprise edition contains direct support from Docker and a variety of other features including extended software maintenance periods.

While Docker images can be stored on your own private servers, Docker also offers a service called Docker Hub which will store Docker images on their servers. Pricing for Docker Hub starts at $0 for individuals running a single docker image all the way up to $500/month for enterprises running 500 private repositories. Additional pricing details for Docker can be found on their website.

Why Use Docker?

There are a variety of benefits to using Docker, including:

  • Consistency: Every server that is capable of running Docker will run and execute the docker image in the exact same way. This makes it easier to ensure performance consistency across multiple servers.
  • Decreased Deployment Time: Docker has a robust API and can be connected to a variety of Continuous Integration tools such as Jenkins. This allows teams to make code changes which are automatically deployed across their Docker Swarm in minutes.

Docker System Requirements

Docker Community and Enterprise Editions, the following system requirements are recommended:

  • OS Support for Linux (Debian, CentOS, Fedora, Redhat) and Windows Server
  • 4GB of RAM
  • 5GB of disk space

How to Use Docker

  • Install


Docker can be installed on a variety of Operating Systems as outlined above. In this example, we’ll walk you through how to install Docker on Debian Linux.

Step 1: Download the Install File

apt-get update

Step 2: Install the Required Packages

apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

Step 3: Add the Docker GPG Key

curl -fsSL$(. /etc/os-release; echo “$ID”)/gpg | apt-key add –

Step 4: Download the Stable Repository

add-apt-repository “deb [arch=amd64]$(. /etc/os-release; echo “$ID”) $(lsb_release -cs) stable”

Step 5: Update the Package Repository

apt-get update

Step 6: Install Docker

apt-get install docker-ce

Step 7: Test Docker

docker run hello-world

Creating A Container

This process outlines the steps to create a simple Docker container:

Step 1: Create and Change Into A New Directory

mkdir dockerapp

cd dockerapp

Step 2: Create a file called Dockerfile

nano Dockerfile

Add the following Content:

# Use an official Python runtime as a parent imageFROM python:2.7-slim# Set the working directory to /appWORKDIR /app# Copy the current directory contents into the container at /appADD . /app# Install any needed packages specified in requirements.txtRUN pip install –trusted-host -r requirements.txt# Make port 80 available to the world outside this containerEXPOSE 80# Define environment variableENV NAME World# Run when the container launchesCMD [“python”, “”]

Save and close the file.

Step 3: Create the Requirements and App Files



—from flask import Flaskfrom redis import Redis, RedisErrorimport osimport socket# Connect to Redisredis = Redis(host=”redis”, db=0, socket_connect_timeout=2, socket_timeout=2)app = Flask(__name__)@app.route(“/”)def hello():try:visits = redis.incr(“counter”)except RedisError:visits = “<i>cannot connect to Redis, counter disabled</i>”html = “<h3>Hello {name}!</h3>” “<b>Hostname:</b> {hostname}<br/>” “<b>Visits:</b> {visits}”return html.format(name=os.getenv(“NAME”, “world”), hostname=socket.gethostname(), visits=visits)if __name__ == “__main__”’′, port=80)

Save these files in the directory you created along with the docker file.

Step 4: Build the Application

docker build -t friendlyhello .

Step 5: Run the Application in the Background

docker run -d -p 4000:80 friendlyhello

Step 6: Publish the Application

Login to Docker:

docker login

Tag the image, substituting an image name, username, and tag :

docker tag image username/repository:tag

Publish the image:

docker push username/repository:tag

You can then go to any machine with Docker and run the following command:

docker run -p 4000:80 username/repository:tag

How to Learn More About Docker

If you’re interested in learning Docker, here are some other helpful resources to help you get started:

Docker Installation Guide

Getting Started With Docker

App Development With Docker

Deploy Your Next Docker Server

ServerMania Hybrid and Dedicated Servers are the perfect option for deploying Docker applications and containers. Consider booking an expert server consultation and we’ll develop a custom server quote for your next Docker server.


Bare Metal Dedicated Servers

A single tenant, physical server allowing you full access to its resources.

Browse servers

Professional Hybrid Servers

Virtualized server platform hosted on enterprise-grade physical servers.

Browse servers

Scalable Cloud Servers

High-performance and highly-available infrastructure.

Browse servers

Managed Colocation

Our next-generation data center facilities.

Browse servers

Your email address will not be published.

There are no comments yet, why not be the first?