Images in Docker

Docker.

You may be asking yourself how does Docker work, here I will explain it to you. First of all let’s suppose I want to run a Container with Ubuntu as OS, If you don’t know what a Container in docker is go to my post where I explain What’s the matter with Docker.

The first thing we need to do is open a command terminal, you can use the one you preffer, I’m going to use powershell of windows because I like that beautiful blue background.

Windows Powershell.

Now let’s see if we have docker properly installed by writing:

docker --version

We should see something like this:

Docker’s Version.

If you do not get this output you probably don’t have Docker installed on your machine, but don’t worry, I have a Linux Ubuntu, Windows and MAC guide for Docker’s installation.

Now we need an Ubuntu version to run inside the Container. How do we run a Container with a Specific OS, will it run smoothly or will it carry the traditional problems we have now with virtual machines? Docker worked this out by using Images, an image is a DockerFile that contain instructions in order to perform an specific activity, in this case we want to run Ubuntu as the OS of our container, in order to achieve that we need the Ubuntu Image for Docker, which we can obtain from Docker’s Daemon, if you are used to git this will not be new to you, because the way Docker manages every image is by saving them on https://hub.docker.com, feel free to take a look over Docker’s Hub and discover all images you can take and use.

Now how to take an image from the hub? let’s see! Write the following command line:

docker pull ubuntu

If we don’t specify a version before pulling the image, Docker will automatically pull the latest version of the image and tag it as latest as you can see here:

That’s all? we have Ubuntu running in a container?, well no, we only have the image of the latest Ubuntu version saved on Docker Hub, we can list the images we currently have available by writing:

docker image ls

Here we can see the list of images we currently have on our machine, but does this works? let’s see, write:

docker run -it ubuntu

The default command Ubuntu container runs is bash, we used the flag “-it” in order to make it interactive and be able to send commands from our command terminal, now let’s see if we are truly in Ubuntu by writing:

ls -lac

this will show the base system files in ubuntu listed like this:

(Now I don’t love that blue background so much) It’s done!, we have Ubuntu running in a container, we can open another shell and write:

docker ps -a

In order to see the detailed list of all containers:

Here we see how the first container named jovial_tesla is up and has been woking during the last 4 minutes, If you download an image you can run it as much as you want without downloading it again.

I hope this guide helped you to understand what images are in Docker and how they work, see you in another guide.

--

--