code

Try Docker with One Command

Yashu Mittal

What is Docker?

Docker is the world’s leading software container platform. Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers. Operators use Docker to run and manage apps side-by-side in isolated containers to get better compute density. Enterprises use Docker to build agile software delivery pipelines to ship new features faster, more securely and with confidence for both Linux, Windows Server, and Linux-on-mainframe apps.

What is a Container?

Containers are a way to package software in a format that can run isolated on a shared operating system. Unlike VMs, containers do not bundle a full operating system - only libraries and settings required to make the software work are needed. This makes for efficient, lightweight, self-contained systems and guarantees that software will always run the same, regardless of where it’s deployed.

Heard of Docker. Right? But still don’t know exactly what it is? I’ll fix that in one sentence:

Docker lets developers bundle an app, together with services it depends on (like databases), into a runnable package called a container.

Okay, maybe it needs a little more explanation than that. Let’s say I’ve been hearing about this cool web server called Nginx, and I’d like to try it out on my laptop. But I already have another web server installed, and I don’t want to interfere with that.

So I install Docker instead.

Then I run this command:

docker run -p 8080:80 nginx

I wait until I see the text Status: Downloaded newer image for nginx:latest in my terminal. Then I launch my browser, connect to http://localhost:8080, and am greeted by this response:

Open the localhost port 8000 on browser

That’s coming from my new personal Nginx server, running on my laptop within a Docker container. If I press Ctrl-C in my terminal, the Docker container shuts down, and http://localhost:8080 no longer responds.

What Just Happened?!

You’re probably wondering how Docker can accomplish all that with one command. Don’t worry, it’s a lot less mysterious once you know what’s going on. Here are the steps Docker goes through when you run docker run -p 8080:80 nginx:

This one short command demonstrates three cool features of Docker:

Other Things to Try

Let’s try a few more commands:

$ docker run -it ubuntu

This one downloads and runs an image with a stripped-down Ubuntu Linux, then sets up an interactive terminal session on it (that’s the -it in the command). When it runs, you’ll be in an Ubuntu shell, working in a file system that’s totally separate from your actual computer’s.

An Ubuntu shell, running within Docker

docker run ruby ruby -e 'puts RUBY_VERSION'

This one downloads an image that includes the Ruby programming language, and runs a small command-line script that prints the Ruby version. You don’t need Ruby installed on your system for this to work; Ruby runs from within the container. If Ruby’s not your thing, don’t worry, the link below has images for many other languages as well.

docker run -it patricknw/xaos

This one’s just for fun. It runs XaoS, an awesome fractal viewer, which just happens to have an ASCII-art mode so it can run in your terminal. There are many key controls available, described here, but the “a” key turns on autopilot for moving around, the “y” key cycles through colors, and the “q” key quits.

There are lots more cool images ready to go at https://hub.docker.com/explore/. If there’s a software package you’ve been wanting to try, but didn’t want the hassle of installing, see if it’s listed there!

Response to “Try Docker with One Command”

Stay current

Sign up for our newsletter, and we'll send you news and tutorials on business, growth, web design, coding and more!