Deploying a Basic Docker Container

Docker is a system for creating and running OS-level virtualization also known as "containerization". Docker runs software packages known as containers which are isolated from each other and can run...

a year ago

Latest Post Automatic Offline Backup With a Raspberry Pi by Tyler Moon

Docker is a system for creating and running OS-level virtualization also known as "containerization". Docker runs software packages known as containers which are isolated from each other and can run different operating systems and software. These containers allow for different projects to run on the same machine regardless of tech stack or dependencies installed on that machine. Containers are configured by images which specify the OS and build steps, which allows for the same exact container to be built over and over again.

Prerequisites

Install Docker Engine

To start with we need to install the Docker Engine. This is the software which builds and runs Docker containers.

Run the following Brew command to install Docker

brew install docker

And it is as simple as that (thanks to Homebrew)

Next login to the Docker Hub so that you can download images for various operating systems

docker login

And log in with your Docker Hub credentials (if you do not have any you can create a free account here)

First Container

To start with we need to download the Alpine Linux image. Alpine is made especially for Docker containers and is very small and lightweight.

docker pull alpine

And now for the Dockerfile to specify how to build and what to run in a container. Create a new file named Dockerfile in an empty directory. Enter the following couple of lines into this new file. You can ignore everything after the '#' as those are just comments.

FROM alpine:3.7 # This specifies which OS to use

RUN apk add --no-cache mysql-client # This will install MySQL server 

ENTRYPOINT ["mysql"] # On container start run 'mysql'

Deploy Container

Now its time to deploy our Docker container. The following command downloads the needed image and creates the container named simple_mysql from the Dockerfile in the current directory

docker build -t simple_mysql .

And now we can run the Docker container and have a working MySQL database running on Alpine Linux

docker run simple_mysql:latest

Summary

In this brief introduction to Docker containers we saw how to:

While this just barely scratches the surface as to what Docker can do I hope that it has helped get you started.

Tyler Moon

Published a year ago

Comments?

Leave us your opinion.