2 Understanding Docker and running Hello World

 

It’s time to get hands-on with Docker. In this chapter you’ll get lots of experience with the core feature of Docker: running applications in containers. I’ll also cover some background that will help you understand exactly what a container is, and why containers are such a lightweight way to run apps. Mostly you’ll be following try-it-now exercises, running simple commands to get a feel for this new way of working with applications.

2.1 Running Hello World in a container

Let’s get started with Docker the same way we would with any new computing concept: running Hello World. You have Docker up and running from chapter 1, so open your favorite terminal--that could be Terminal on the Mac or a Bash shell on Linux, and I recommend PowerShell in Windows.

You’re going to send a command to Docker, telling it to run a container that prints out some simple “Hello, World” text.

Try it now:

Enter this command, which will run the Hello World container:

docker container run diamol/ch02-hello-diamol

When we’re done with this chapter, you’ll understand exactly what’s happening here. For now, just take a look at the output. It will be something like figure 2.1.

Figure 2.1 The output from running the Hello World container. You can see Docker downloading the application package (called an “image”), running the app in a container, and showing the output.

2.2 So what is a container?

2.3 Connecting to a container like a remote computer

2.4 Hosting a website in a container

2.5 Understanding how Docker runs containers

2.6 Lab: Exploring the container filesystem