Docker Images - Intro for beginners
Yet another blog about docker that could be found in documentations, you might think. Legit opinion. But this is for those who don't want to be pointed to the bunch of documentation. And for those who would like to have some real use case in front of them when learning new concepts.
It's for beginners. So for those who heard about docker but never tried them. For those who heard their colleagues talking about it, but felt insecure to even ask how does it work. I might turn this into series of articles, we will see.
Real life dev scenario - PostgreSQL on your next project
Let's make a scene. Not the drama scene, but just to relax our mind a bit. This is not a post where you are presented a bunch of commands that's it. This should have a soul 😊.
You found out that your next project will involve, say, PostgreSQL. You never worked with it, you want to see how it looks like, and to prepare yourself for that project. Also, you already have a local machine set up for the current project. with totally different technologies. You don’t want to make more "mess".
Docker Hub will be your starting point in many cases, so let’s write a few words about it. We will use it also in this workshop to find images we need. It’s also a place where images are documented, so you’ll probably come back here many times.
Also, a tip for the future, start asking yourself "Does XYZ have a docker image I can use?". Open it now and try searching some images, for example,
mysql, wordpress, ghost, elasticsearch, php, java, maven, gradle, python. You see my point? You can find almost anything as a docker image.
You may notice this OFFICIAL IMAGE mark. That means the people who developed that technology, are most likely involved in developing and maintaining the docker image. There are other advantages, of course, check the documentation.
But it’s ok to use unofficial ones, too. Especially if you are experimenting with something. For example, my colleagues were developing an app in
React Native. I didn’t have anything setup for compiling React Native project. All I wanted was to build an
APK file and use it on my mobile phone. So I’ve just pulled the unofficial image that has everything installed there. Built my APK file and that’s it.
Ok, that’s enough for Docker Hub. Lets' move on.
The first step is to check out Postgres image on Docker Hub. This is the link, but feel free to go there and search it directly.
If you take a look at the description, you’ll see the supported tags and respective
Dockerfile links. Consider tag as a version for the moment. There is also a whole tab dedicated to TAGS where you can find all the tags of this image. But the ones in the Description tab are supported ones. At the moment, supported tags go back down to version
9.5.22. Also, versions in the tag are very likely to represent the version of the technology in the image. For example,
Python image tagged as
3.6.8- stretch will have
Python v3.6.8 in it. I’ll explain this
OK, now we want to get a
Postgres image. As this blog is static, we will stick with the version
11.8. Postgres meanwhile released another tags, but for the sake of the blog we will use the
version 11. The blog was tested with the version
11.2, so we should stick with the major version 11.
There are two groups of tags, you may notice
# output 11.8, 11 11.8-alpine, 11-alpine
You may wonder what’s the difference.
Let’s pull both of them with commands below, and I’ll explain a bit while you wait for them to download. Yes, actually stop reading the blog and execute these two commands, one after another.
$ docker pull postgres:11.8 $ docker pull postgres:11.8-alpine
OK, as you might see in browser (on the Ducker Hub page), each tag in one line links to the same
Dockerfile. So it doesn’t matter if you are using
11. At the moment of writing the initial blog article, in this line there was also a
latest tag. The
latest version back at the time was
11. Now the latest is moved to the
version 12. There are also beta versions 13 which will eventually become stable and thus
latest. You get the point. Be careful with tag latest, as it will switch to the newer version in some time. I would suggest you to use specific tags instead of the
latest. As you would do with any other dependencies and libraries.
But what about this
alpine group of tags? At this moment your images may be ready, if not wait till they are, and execute
$ docker images
You may see something like this, (your results may vary slightly):
# output postgres 11.8 ... 312MB postgres 11.8-alpine. ... 70.8MB
It's all about sizes
Notice the difference in the size of those docker images. Docker is all about minimising resources you need to run something. It would be way heavier, for example, to run a complete virtual machine. Docker is not a virtual machine but that’s beyond the scope of this material. With Docker, you can have running
Postgres server in
70 MB. Consider Docker containers as an isolated process that runs on your machine.
If you open each of the Postgres
Dockerfiles (find the links on the Docker Hub, I mean it, go and click it) you will see they are built on top of different Docker base images. I’m talking about
Postgres image documentation. There will be something like
FROM debian:stretch-slim and
FROM alpine:3.11. You don’t have to understand anything about
Dockerfile for now. Let’s just say that our
Postgres images have to run on some architecture, and in this case, it’s Debian or Alpine. You may see different tag suffixes, such as
jessie and they refer to the base image they are built on. The size of an image, and also a set of available tools will depend on that, as well. In the end, they throw out all unnecessary things to achieve the small size. Consider that later when you get familiar with Docker. We’ll use
alpine images for now. If you check Alpine distribution site you’ll notice this motto:
Small. Simple. Secure.
Think about what you've read. It may be all confusing. That's ok. Feel free to read it again. Docker is a complex thing. Many will try to grasp as much as possible about Docker and it will just cause a mess in their head. Especially if you're new into this. That's why I provided only fraction here. But this fraction will be enough for your next steps.
Thanks for reading.
If you liked the style of this article, and you would like to "get on your feet" with Docker, I have good news for you. This is part of material I'm using for my internal Docker workshops, and I made it available to everyone to purchase it. After finishing the 20 pages of interactive course, you'll be comfortable to speak with your colleagues about Docker without hesitation.
And the whole workshop is organised in real life dev scenarios.
- Setting up a postgresql with db manager
- Making sure your database entries survive re-creation of docker containers
- Setting up web server and packing it with pre-loaded application and more
Where's the special offer? Well, I'm offering 35% discount if you use the promo code
Check it out here (promo link already included so you don't have to type it 🤗) 👉 Become Proficient with Docker in 2 hours