top of page

How to make first steps with Docker?


Introduction


No applications, no business - rings the bell? In my previous post, I made the introduction to the containerization and compared it with the virtualization technologies. Hopefully, you also got to know Will and one of his struggles a bit better. In this blog post, I am going to show you how to start your journey with a particular container technology called Docker. You might remember that word 'Docker' by no means is a synonym of 'container'. Docker is the most popular open-source technology majorly sponsored by the company named Docker Inc.

Docker doesn't equal containers, but a container does equal a process. The process starts from the definition and creation of rudiments (i.a. binaries or/and libraries) that lead to scale. There are short- and long-running processes. Batch jobs are an example of later, whereas webservers are related to the former type.

I hope the following content is a great beginner's cheat sheet and soon you'll be as fluent as Will is :-)


Roll your sleeves up and get ready


I would probably need to start with installation instruction. Still, there are already plenty of resources, including the Docker official page, with comprehensive instructions and download links. Therefore please allow me to skip this part. Nonetheless, what is worth mentioning before going directly to the installation is that if you are Windows user, please make sure you have Hyper-V enabled. You can use this official Microsoft resource to set it up.


Good old 'Hello world.'


You have the Docker install now! Are you not assured? Alright, let's make sure you've got it.


Open your terminal window and type in our first ever docker command:

docker version

The output of this one is breaking down into two elements: client and server (daemon). The top part of it displays the client's details, and at the bottom, you see server details. In my case, as you can see in the client piece, I run the Docker on macOS local machine. So the client and server are running locally on my laptop at this moment. I am emphasizing this because, in some cases, you might have the server running on remote instances (e.g., AWS EC2).


Another useful command to familiarize yourself with newly install software would be:

docker info

First, you can see a number of running, paused, stopped container, and count of images. Next, you see some of the version details similarly to the previous version command. Using docker info is an excellent and swift way to check how the things are on Docker host.

I am positive you can't wait when you run your first container. Let's do that! As the activity word suggests, the command we need to use is

docker run hello-world

As simple as that - yes ;-)


Now let's see what just happened. We break down into pieces:

  1. docker - spins up Docker binary in the background (this is common for all commands as you already probably noticed);

  2. run - this is a usual way of asking Docker to run a container for us;

  3. hello-world - specification of what image to use as a base for the container.


When submitted, the client asks the server if the image is stored locally. I don't have the image saved locally - this is why we see "Unable to find image 'hello-world:latest' locally". In this case, the server goes to the place called Docker Hub and pulls the image from there. The printed output describes well what was done by running the above command.

Let's rerun docker info to see if anything changed. Now we see that we've got 1 image and 1 container. We also now that this container is currently in a stopped stage.


Simple cheat sheet for you to get started


There are lots of different commands you can find in the official documentation. It is easy to get overwhelmed when you are making the first steps. I've shortlisted the most indispensable ones for you right here.


docker version - show the Docker version information;

docker info - display system-wide information;

docker run - run a command in a new container;
    --name - assign a name to the container
    --rm - automatically remove the container when it exits
    
docker ps - list (running) containers:
    -a/--all - show all containers
    --last/-n - show n last created containers
    
docker pull - pull an image or a repository from a registry (you can have a local registry or remotely such as bespoke Docker Hub - you can find there plenty of pre-built images to start with);

docker stop - stop one or more running containers;

docker rm - remove one or more containers;

docker rmi - remove one or more images.

Wrap up


You are one step closer to be as cool as Will is doing all of this fancy stuff with containers. I am happy you made it through this post and got at least one of the listed commands in your favorites. I know it might take a bit of time to make yourself comfortable with containers as a process and a new way of thinking when running applications using images. You will find it ridiculously easy after several months of practice, and very soon, you won't be able to imagine life without Docker.

In the next post, I am going to show you one of the use cases I've used the Docker for. I will show you how easy it is to set up Apache Spark using containers and make use of it literary in a couple of minutes.


You made it to your first container - really proud of you!


40 views0 comments

Recent Posts

See All

Comments


bottom of page