Technical Articles
Understanding containers (part 01): Run, Docker run!
Even if you haven’t worked with containers yet you might have heard that “containers are like light-weight virtual machines“.
And that’s the way we are going to use them at the beginning too. Along the way we will clarify differences between traditional VMs and containers.
Graphical UI – forget for now
If you used VM hypervisors on your computer, then I should assume you used an application with graphical UI — like VMware Player — to manage, configure, start or stop your virtual machines.
At the time of writing this post, the Docker Desktop is at the version 2.1 and comes with such a UI application as well. It is called Kitematic and its Alpha version is part of Docker Desktop installation.
In its current alpha version it is pretty much useless for what we want to do here, so let’s forget about it in the context of the current blog. Through the rest of the series we will focus mostly on command line tools.
If you are using Kitematic and would like to share your experience or tips&tricks with it, please share a link to your content in comments.
Our first toy: OrientDB
For our initial experiments with Docker we will play with the community edition of OrientDB.
Never heard about OrientDB so far? Well, it is about time! OrientDB is “the DBMS supporting Graph, Document, Reactive, Full-Text, Geospatial and Key-Value models in one Multi-Model database“. And its community edition is an open source. It is one of Top 3 databases to process graph data accordingly to https://db-engines.com/en/ranking/graph+dbms.
Run, Docker run!
Without further ado, let’s run our first container!
I assume you have access to Docker and it has access to the Internet (as described in the previous post). So, let’s run OrientDB database.
docker container run orientdb
If you have never ran it before, then you should see the output similar to this.
Yay, out of nowhere our first container is running! Or for all the purists among us: “Yay, our first container is up and the command to start OrientDB server is running!” There is a difference between these two statements, but we will get into details later.
And this first container did not came from nowhere. It was downloaded from the orientdb
repository hosted by public registry called Docker Hub: https://hub.docker.com/_/orientdb.
Let’s celebrate!! …or not?
Even though we have a database running in our very first container, there is no easy way to access it right now:
- Even though it exposed two services on ports
2424
and2480
they are not visible outside of the container. - We do not know the password for the database’s
root
user, as it was auto-generated inside the container.
Let’s run it properly this time
Have a look at this command (without running it yet):
docker container run --detach --publish 0.0.0.0:2480:2480 --publish 0.0.0.0:2424:2424 --env ORIENTDB_ROOT_PASSWORD=root docker.io/library/orientdb:latest
Say whaaat?!! ?
Ok, do not get scared and discouraged at this moment. We agreed on avoiding graphical UI, so everything needs to go into the command line.
Let’s have a look what it means:
- We run the
docker
CLI tool — that’s obvious. - We tell it to execute a command related to
container
Docker object (there are several kinds of objects you deal with using Docker, but we will get to that later)… - …and the command is
run
, which creates a new container from the Docker imagedocker.io/library/orientdb:latest
. - This is the image from
orientdb
repository which has the taglatest
and stored in the public https://hub.docker.com registry, as can be identified bydocker.io/library/
namespace. - Everything in between the command and the image name are options specific for the docker command being executed. You can see the list of possible options and their meaning by attaching
--help
at the end, i.e.docker container run --help
. - Similarly you can call for help for the tool using
docker --help
and for the list of commands related to container object usingdocker container --help
. - What are the options we are going to use?
--detach
says that the container should start in the background;
--publish 0.0.0.0:2480:2480
says that the port 2480 used by the application inside the container should be exposed to the host computer and mapped to the port 2480 accessible via any client IP because of0.0.0.0
mask.
--env
is the way to pass the environment variable to the container, like the databaseroot
user password required during the first setup of the OrientDB database server
I hope it all makes sense so far.
Laziness is the Mother of Progress
But it is way too much typing, so luckily for lazy guys like me Docker comes with some help.
- Most common management commands have shorter forms, like
docker run
is equivalent todocker container run
. - Similarly the most common options have their short forms too, like
-p
for--publish
,-d
for--detach
, or-e
for--env
. You can check this by runningdocker run --help
as mentioned before. docker.io/library/
is the default registry and thelatest
is the default tag, soorientdb
is the same asdocker.io/library/orientdb:latest
- And if you do not specify an IP in the
-p
option, then0.0.0.0
is assumed by default.
Uff… So, finally we got to the command that we can and should run now!
Firstly, press Ctrl+C
to stop the previously running container (started with docker container run orientdb
command).
Secondly, from the command line run the following complete and neat command:
docker run -d -p 2480:2480 -p 2424:2424 -e ORIENTDB_ROOT_PASSWORD=root orientdb
Once executed all you see in return is just some long hexadecimal string, like 897c8bd896e2cb3ec664a895cca86a3bf16ea42640a67b6ee1ae5193b46683f5
in my case. We will call it a container’s technical id for the moment.
You can now use this container ID in the commands, like to check the log of the container with docker logs 897c8bd896e2cb3ec664a895cca86a3bf16ea42640a67b6ee1ae5193b46683f5
, which is the short form of the docker container logs
command as you can guess by now.
Technical ID? I am a human!
I am a human. And I am lazy, And Docker came with some handy features for that.
Tip 1: Shortening a technical id
It is enough to use only as many first characters of the technical ids as they make unique combination among all technical ids used in your environment.
So, in my example instead of typing docker logs 897c8bd896e2cb3ec664a895cca86a3bf16ea42640a67b6ee1ae5193b46683f5
I can just type three first characters to get the same:
docker logs 897
Tip 2: Human readable names
You can call your running container by some human readable name, so let’s call it myorientdb01
for now, by using the shorter version of docker container rename ...
command:
docker rename 89 myorientdb01
Yes, it was enough to use even first two characters in the command above to uniquely identify my running container. Obviously you need to use digits from your running containers 😉
Now you should be able to check logs simply typing the following.
docker logs myorientdb01
Tip 3: Automatically generated container names
Let’s have a look at containers we have created so far with the following command, which is (less obviously this time) is the short version of docker container list --all
. By default this ps
command displays only running containers, so we added the option -a
to display containers in all states.
docker ps -a
In the last column you can see, that even the first container, which we ran, got its human readable name sad_tu
. It was automatically generated by Docker from the random combination of some adjective with some noun.
We can use this name (sad_tu
in my case, but some different on your machine) to delete that container as we do not need it anymore. The following command is the short version of docker container rm --force
to remove (delete) existing container.
docker rm -f sad_tu
We use the --force
option, because the previous container may still be running — depending if you are using Docker Desktop or Docker Toolbox and the way you exited it.
Tip 4: Name a container at run
You do not need to leave it to Docker to autogenerate the name of the container you run for the very first time. We could have included --name myorientdb01
option already into the run command, like docker run --name myorientdb01 -d -p 2480:2480 -p 2424:2424 -e ORIENTDB_ROOT_PASSWORD=root orientdb
to name your new container the way you want.
I’ve got it running in the container. Now what?
Now let’s try to connect to the Studio or that OrientDB database from myorientdb01
container.
You might have noticed that line from the log, when you executed docker logs myorientdb01
:
INFO OrientDB Studio available at http://172.17.0.2:2480/studio/index.html
The IP 172.17.0.2
is the address seen only inside the container. But the port 2480
was published and mapped to the same port of the Docker host, when we run it. So, now depending on the Docker you are using the host address will be:
localhost
, if you are running Docker Desktop, or- the result of the
docker-machine ip
command, if you using Docker Toolbox.
Here is the screenshot from my Macbook with Docker Desktop on it and OrientDB running. I opened the URL http://localhost:2480/studio/index.html
.
Got so far? Congrats!
If you got so far, then hopefully you learned some of the Docker basics to run the new container and to understand some of the main concepts.
And since you have OrientDB running on your machine, then it is time to have some fun with it. Just go to:
- http://orientdb.com/docs/3.0.x/gettingstarted/tutorials/ to start with basics, or
- import from the cloud some of the sample databases using the user
root
and the password defined withORIENTDB_ROOT_PASSWORD
environment variable earlier
There is a free Udemy course available as well: https://www.udemy.com/course/orientdb-getting-started/
Have fun!!
Before you go
Once you are done playing with OrientDB and Docker for today, just remember to stop the container.
docker stop myorientdb01
Next time you want to continue playing with your instance of OrientDB just start it again…
docker start myorientdb01
…and check in logs when it is fully started.
We will keep digging into Docker and containers in next posts. I will tag these posts UnderstandContainers for easy search.
Stay tuned!
-Vitaliy (aka @Sygyzmundovych)
Witalij The Great!!! Even me can work with that. Thanks for the effort.
Philipp The Wise!!! Your words mean a lot to me. Now it makes two of us, who even made it working ;-P
Hi Witalij,
I love the Docker/Kubernetes direction and tutorial, especially when it eventually ties in some SAP tech. I’ve been experimenting with SAP Data Hub over the last 2 years, and have just recently come back to running the SDH 2.4+ Dev Edition on Docker on both Mac and Windows. Docker and Kubernetes are really great environments!
I haven’t tried HANA in a Docker container yet, and not sure why you’re featuring OrientDB (maybe just HANA Express Edition RAM requirements?), but I’m looking forward to where you’re going with this. Perhaps a geospatial theme? Command “docker search HANA” does show several images in Docker Hub, though.
I agree Kinematic is relatively useless as a UI for Docker, and think it’s been alpha forever. I only use it on an old 2008 Mac Pro (without VT-x instruction set) where I must use Docker-toolbox. It’s helpful for illustrating the ports and volumes of the VirtualBox VM it creates (screenshot). I know the host is also available via the CLI command “docker-machine ip”, but again…lazy. Localhost works fine in Docker Desktop for Mac or Windows, but not for Docker Toolbox.
A few other nifty docker commands of note to use with containers are:
I’m honestly looking forward to where you’re going with this, beyond an intro to Docker and into Kubernetes. We await the next adventure!
Thanks,
Doug
Hi Doug. Thank you for the comment and sharing experience. Much appreciated!
The reason for starting with OrientDB is because it is the open source db from SAP, and simpler than HANA to start in the Docker. And - because I wanted this series to go as well into understanding of containers, not just a cheat-sheet of Docker commands - I found OrientDB more fitting into get-started tutorials. The plan is to move as well to HANA Express and Data Hub dev edition in later blogs, when moving to some more advanced topics of containers.
Have a good week ahead!
-Vitaliy
Ah! I completely missed that OrientDB is an SAP company and db! I just spotted SAP in the graphic on the about us page: https://orientdb.com/about-us/
I also just found your series intro & overview post laying out plans to add HANA and SDH, too: https://blogs.sap.com/2019/11/21/understanding-containers-with-docker-and-sap/
Carry on!
I just upgraded my Docker Desktop to 2.2 version and Kitematic is gone from the installation. Now it is replaced by something called "Dashboard" that seems even more reduced (but - probably - stable, as there is no "alpha" next to it)
I noticed Dashboard too when I upgraded to 2.2 before going through your part 4 blog. Per the Docker blog, it looks like Kitematic will be "archived" altogether this year (It's still installed on my system). It's good that Dashboard is integrated and consistent between MacOS and Windows, but it doesn't seem to add much functional value at this point. Comparing Kitematic & Dashboard side by side, it seems you can still inspect the container settings by clicking on the container, but network settings are missing. I'll continue to rely on the CLI for most everything like start/stop/inspect, etc.
https://www.docker.com/blog/docker-desktop-release-2-2-is-here/
Philipp, Douglas: the second part is off the press: https://blogs.sap.com/2019/12/06/understanding-containers-part-02-inside-a-container/
Wish SAP hired more people like you. Perfect blog!
Do you know how to use WSL2 + docker to install HANA Express with apps on Win 10 2004? Or maybe point me to a straightforward blog like yours?
Thanks.
Hi Sagar Sheokand. Thank you for your nice words.
To your question: have you seen that recent post Installing SAP HANA, express edition into WSL2 by Thomas Jung?
Looks exactly what I was looking for. Top job! Thanks.
(I think the only reason I missed this is because it's just a week old. Have scoured the whole internet to look for a proper solution.)