Docker for Beginners Part 3 - Docker Image and Docker Container

Part 3 - Docker Image and Docker Container


This is the Part 3 from the Docker series - Docker for Beginners in 8 Parts. In this post we're going to explore Docker Images and Docker Containers!

  • Part 1 - Differences between Containers and Virtual Machines
  • Part 2 - Overview of Docker Installation for Mac and Ubuntu
  • Part 3 - Docker Images and Containers
  • Part 4 - Exploring Docker Images in Details
  • Part 5 - Exploring Docker Containers in Details
  • Part 6 - Building Custom Docker Images with Dockerfile
  • Part 7 - Pushing our Great Docker Image to Docker Hub
  • Part 8 - Keeping MongoDB Data with Docker Volumes

A simple comparison between Docker Images and Docker Containers could be:

A Docker Image is the prototype, the skeleton to create your container.

Docker Image is a recipe for a cake!

A Docker Image describes what your container will have like applications, exposed ports, mounted volumes, script to be executed in the start up, etc.

A Container is the environment itself up and running, ready for your application

Container is the real cake from the recipe!

So, we must use Images to start and run Containers, right?

And you can ask:

Where does that Docker Image come from?

Docker Images come from Docker Repository! Yeh, this is a new term and we will see more about that in details.

But for now, we just need to know that Docker has a repository to keep Docker images.

Those images can be images to run containers with Linux, Tomcat, Nginx or Java for example, together or not.

Ok, let's hacking some Docker code!

First Docker Image

We will get our first Docker Image from the Docker Repository!

This image will be the Docker Image for Tomcat applications. Nice, isn't?

To get that image, we must type the docker pull command in the terminal followed by the image name, as below:

Easy! Notice that an image has been downloaded from the Docker Repository. You will see an output showing something like this:

Perfect! Now we have the Docker Tomcat image locally. But remember, an Image is just a prototype, a skeleton, a cake recipe! We can't eat recipes 🙁

So, let's make the cake!

First Docker Container

Now it's time to eat! Let's make our cake from the Docker Tomcat Image.

To run our first container based on that image, let's use the docker run command:

Just that! You can go to your chrome preferred browser and type the address:

And you will see the Tomcat default page up and running \o/

Notice that we're using the default port 8080. Maybe you already have another application running in this port, since it is really famous port 🙂

Let's change this behavior by using the flag -p while starting the docker container to indicate which port should be used. Type Ctrl+C on the Terminal to stop the current Tomcat Container and type the command:

The pattern used here was:

Now you can access the Tomcat default page from the address:

Docker World

After this first emotion, let's take a step back to the boring important theory. Don't run away!

Just to learn and overview all of the most important names in the Docker World, we will see each of them in this part of the series:

Docker Image

Just to remember, a Docker Image is a recipe that contains the instructions to start and run containers. Again, this is the cake's recipe, not the cake itself.

Docker Container

Now it is the cake! Containers will run your application using the environment that will be built based on its Docker image.

For example, you could run a Java Application in a Linux Container, that was built from a Docker Ubuntu Image

Docker Registry

Docker Registry is the place where we can push or pull Docker Images. This place can be private or public and it stores and shares lots of images.

You can, for example, push your particular images to a Docker Registry to keep that images public and developers could pull that image and build its containers and your image could have success in the world!

Docker Repository

Docker Repository is a namespace that is used for storing a Docker Image. I know, the first impression is that Docker Repository and Registry is the same thing.

The difference is that the Repository is just the namespace that indicate which address should be used to get your images on Docker Registry

Docker Hub

Docker Hub is the Official Docker Registry to push and pull images. You can create yourself your own Docker Registry if you want (we're going to see it with Docker and Kubernetes in another post!).

To keep practical, let's see my Registry on the Docker Hub, that has a namespace as Docker Repository address.

This is one of my public repositories:

Notice that this is a namespace to find my public Docker Image.

The DockerHub is the Docker Registry

This means that images can be stored in the DockerHub

That's it!

Let's explore Docker images in more details in the next post of the Docker Series: Part 4 - Docker Images in Details


Follow us to keep up to date!

Alexandre Gama

Alexandre Gama

Hacking Code Founder

Hacking Code Founder and Writer, Passionate Senior Software Engineer and Team Leader at @Elo7, Teacher of several courses at Caelum, Speaker at many conferences and terrible guitar player.
Docker for Beginners Tutorial - Containers vs Virtual Machines - Hacking Code

Part 1 - Containers vs Virtual Machines

This is the first Post of the Dockers series! We're going to explore differences between Containers and Virtual Machines!

Docker for Beginners Tutorial - Docker Installation - Hacking Code

Part 2 - Docker Installation on Mac and Ubuntu

Before hacking Docker commands we must install Docker!

Docker for Beginners Tutorial - Docker Images and Containers

Part 3 - Docker Images and Docker Containers

What's the differences between Docker Images and Docker Containers?

Docker for Beginners Tutorial - Docker Images

Part 4 - Docker Images in Details

It's time to explore more about Docker Images!

Docker for Beginners Tutorial - Containers in Details

Part 5 - Docker Containers in Details

It's time to explore more about Docker Containers!

Docker for Beginners Tutorial - Dockerfile - Hacking Code

Part 6 - Custom Docker Images with Dockerfile

Let's build your own custom Docker Image with Dockerfiles

Docker for Beginners Tutorial - Docker Hub

Part 7 - Pushing Docker Images to Docker Hub

Pushing your own great Docker Images to Docker Hub to exposes it to the World!

Docker for Beginners Tutorial - Docker Volumes - Hacking Code

Part 8 - Docker Volumes with MongoDB

Stop losing your data in the Docker Container by using Docker Volumes


Leave a Reply

Share This
Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: