Click here to Skip to main content
13,736,808 members
Click here to Skip to main content
Add your own
alternative version

Stats

5.8K views
18 bookmarked
Posted 13 Aug 2018
Licenced CPOL

Getting Started With Docker

, 13 Aug 2018
Rate this:
Please Sign up or sign in to vote.
Getting started with Docker by installing it and pulling a small image

Introduction

In this article, we'll be walking through setting up Docker, pulling down a small Docker image, and running it.

Although this article was created as a way for CodeProject members to enter our Docker Challenge contest, it also serves well as a very basic tutorial if you've never used Docker before and are looking to get started.

What is Docker, and Why Should I Care?

Docker, and containerization in general, have exploded in popularity over the past few years. Popularity isn't always a good reason to use technology, though. The longer your software development career has been, the more likely it is that you've been drawn in by a new, shiny, popular bit of tech that ended up being a nightmare.

Docker, I believe, is one of those tools that actually lives up to the hype. A Docker container, as its name implies, is an isolated environment that your application(s) run inside. In practice, it works a bit like a virtual machine, but with a lot less overhead. A VM typically virtualizes an entire computer - CPU, RAM, input and output devices - plus an entire operating system running on top of it. Docker, in contrast, runs on top of an already installed OS and shares its kernel and RAM with the host OS. So there's no need to pre-allocate any CPU or RAM the way you would with a VM. The processes running inside a container simply use what they need, leaving the rest available for other containers or processes running on the host OS.

Typically, a Docker container holds a single application. The container also has all of the application's runtime dependencies, so there's no need to install anything or perform any setup steps - you simply pull a docker image to the machine where you want to run it, and then start the container.

Docker also uses immutable file systems - so if you have several applications that use a complex base image, like Ubuntu, you don't need to waste disk space by keeping a separate copy of the Ubuntu image for each application. Instead, you'll have a single copy of the Ubuntu base image, and each application's file system will contain only the differences between base image and the application image.

There's a lot more to Docker than we've covered here. If we tried to cover everything at once, this article would be long and boring! When trying out a new bit of technology, it's often best to try it out and see it in action, and then do a deep dive to learn everything. Since that's the approach we're going to take, we'll move on to installing and running Docker.

Installing Docker

Docker is available for Windows, Linux, and MacOS. We'll cover the installations steps for each OS.

Windows

Download Docker from https://download.docker.com/win/stable/Docker for Windows Installer.exe.

Once the download im complete, run the installer. If given the option to choose between Windows and Linux containers, choose Linux.

MacOS

Download Docker from https://download.docker.com/mac/edge/Docker.dmg.

When the download is complete, open the .dmg file and run the installer. When the install is finished, you'll see a Docker application in the your Mac's applications folder. Run this application to start the Docker daemon.

Linux

Navigate to https://get.docker.com/. This address contains a bash file, and in a comment block near the top of the file, you'll see instructions on how to set up Docker on Linux. At present, setting up Docker requires running two terminal commands:

$ curl -fsSL get.docker.com -o get-docker.sh
$ sh get-docker.sh

Many Linux distributions offer a Docker package that can be installed via the distro's package manager. Some of these Docker packages are very old, however. As long as the version of Docker offered via your Linux distro is fairly recent - released in the past 12 months - it should be new enough to finish this tutorial.

Pulling a Docker Image

When Docker installs, it typically adds itself to your system path, and so can be run from anywhere when you open a command prompt or terminal. So to get started, let's open a terminal:

  • On Windows, open a Command Prompt or Powershell window.
  • On MacOS, open Terminal.app (or iTerm, if you prefer it).
  • On Linux, open xterm or whichever terminal program your Linux distro ships with.

Now, in your terminal window, run the following command:

docker pull codeproject/docker-contest

When you run the command, you'll see Docker pulling the CodeProject contest image from Docker Hub. The image should download quickly, as it is based on Alpine Linux, which is quite small - only a few megabytes.

Generating Your Contest Entry Code

Now that you've pulled the CodeProject contest image, it's time to generate the code you'll use to enter the contest! To do this, run the following command in your terminal:

docker run -it codeproject/docker-contest

The image will start, and you'll see it ask for your CodeProject member number. You can find your member number on your profile page, directly above your photo or avatar. Enter your number, and the CodeProject contest Docker image will give you a code you can use to enter the contest. You can find the contest entry page here.

And that's it! You've installed Docker, pulled down an image, and run it inside a Docker container. We've just scratched the surface of what's possible with Docker, but now that you've installed it and used it, you're in a good position to dive in to some more advanced tutorials.

Now What?

Looking to try some additional things with Docker?  

You might try these commands:

docker run hello-world
docker --version
docker info

Also, consider checking out the excellent overview and tutorial offered on the Docker site:  https://docs.docker.com/get-started/.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ryan Peden
Software Developer CodeProject
Canada Canada
I spent 5 years working for Ottawa startups before returning home to Toronto and landing at CodeProject.

I'm a .NET and JavaScript developer by day, but in the evening you'll often find me cooking up projects in Ruby, Haskell, Clojure, Elixir, and F#.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
BugDocker pull does not work on Docker for Windows Pin
VSarvothaman5-Oct-18 0:58
memberVSarvothaman5-Oct-18 0:58 
QuestionIMHO Pin
John Simmons / outlaw programmer3-Oct-18 4:06
professionalJohn Simmons / outlaw programmer3-Oct-18 4:06 
QuestionUnauthorized to pull docker image Pin
number-phi12-Sep-18 5:08
professionalnumber-phi12-Sep-18 5:08 
QuestionCocker contest contribution done! Pin
Gunnar S24-Aug-18 4:01
memberGunnar S24-Aug-18 4:01 
QuestionYou may like to add a warning notice ... Pin
Richard MacCutchan22-Aug-18 5:03
protectorRichard MacCutchan22-Aug-18 5:03 
QuestionDocker Via DigitalOcean Pin
raddevus17-Aug-18 5:03
mvpraddevus17-Aug-18 5:03 
AnswerRe: Docker Via DigitalOcean Pin
Ryan Peden17-Aug-18 11:07
staffRyan Peden17-Aug-18 11:07 
QuestionUnfortunately the hyperlink to the page in which I need to enter the secret code generated is missing. Pin
Arthur V. Ratz16-Aug-18 19:17
mvpArthur V. Ratz16-Aug-18 19:17 
AnswerRe: Unfortunately the hyperlink to the page in which I need to enter the secret code generated is missing. Pin
Ryan Peden17-Aug-18 2:52
staffRyan Peden17-Aug-18 2:52 
GeneralRe: Unfortunately the hyperlink to the page in which I need to enter the secret code generated is missing. Pin
Arthur V. Ratz17-Aug-18 2:55
mvpArthur V. Ratz17-Aug-18 2:55 
GeneralRe: Unfortunately the hyperlink to the page in which I need to enter the secret code generated is missing. Pin
Ryan Peden17-Aug-18 2:58
staffRyan Peden17-Aug-18 2:58 
QuestionCodePoject member number Pin
EoRaptor14-Aug-18 18:20
professionalEoRaptor14-Aug-18 18:20 
AnswerRe: CodePoject member number Pin
Ryan Peden15-Aug-18 6:31
staffRyan Peden15-Aug-18 6:31 
GeneralRe: CodePoject member number Pin
Arthur V. Ratz17-Aug-18 0:25
mvpArthur V. Ratz17-Aug-18 0:25 
GeneralRe: CodePoject member number Pin
Ryan Peden17-Aug-18 2:47
staffRyan Peden17-Aug-18 2:47 
GeneralRe: CodePoject member number Pin
Arthur V. Ratz17-Aug-18 2:53
mvpArthur V. Ratz17-Aug-18 2:53 
GeneralRe: CodePoject member number Pin
raddevus17-Aug-18 4:57
mvpraddevus17-Aug-18 4:57 
GeneralRe: CodePoject member number Pin
Ryan Peden17-Aug-18 11:05
staffRyan Peden17-Aug-18 11:05 
GeneralRe: CodePoject member number Pin
raddevus17-Aug-18 11:09
mvpraddevus17-Aug-18 11:09 
QuestionCannot find docker contest entry page, link seems to be missing Pin
Gunnar S13-Aug-18 9:23
memberGunnar S13-Aug-18 9:23 
AnswerRe: Cannot find docker contest entry page, link seems to be missing Pin
Ryan Peden15-Aug-18 6:28
staffRyan Peden15-Aug-18 6:28 
GeneralRe: Cannot find docker contest entry page, link seems to be missing Pin
Gunnar S15-Aug-18 6:56
memberGunnar S15-Aug-18 6:56 
GeneralRe: Cannot find docker contest entry page, link seems to be missing Pin
Ryan Peden15-Aug-18 7:16
staffRyan Peden15-Aug-18 7:16 
GeneralRe: Cannot find docker contest entry page, link seems to be missing Pin
Ryan Peden17-Aug-18 2:53
staffRyan Peden17-Aug-18 2:53 
GeneralRe: Cannot find docker contest entry page, link seems to be missing Pin
Gunnar S17-Aug-18 3:28
memberGunnar S17-Aug-18 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 13 Aug 2018
Article Copyright 2018 by Ryan Peden
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid