Skip to Content
Technical Articles
Author's profile photo Witalij Rudnicki

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:

  1. Even though it exposed two services on ports 2424 and 2480 they are not visible outside of the container.
  2. 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:

  1. We run the docker CLI tool — that’s obvious.
  2. 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)…
  3. …and the command is run, which creates a new container from the Docker image docker.io/library/orientdb:latest.
  4. This is the image from orientdb repository which has the tag latest and stored in the public https://hub.docker.com registry, as can be identified by docker.io/library/ namespace.
  5. 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.
  6. Similarly you can call for help for the tool using docker --help and for the list of commands related to container object using docker container --help.
  7. 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 of 0.0.0.0 mask.
    --env is the way to pass the environment variable to the container, like the database root 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.

  1. Most common management commands have shorter forms, like docker run is equivalent to docker container run.
  2. 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 running docker run --help as mentioned before.
  3. docker.io/library/ is the default registry and the latest is the default tag, so orientdb is the same as docker.io/library/orientdb:latest
  4. And if you do not specify an IP in the -p option, then 0.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:

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)

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Philipp Nell
      Philipp Nell

      Witalij The Great!!! Even me can work with that. Thanks for the effort.

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki
      Blog Post Author

      Philipp The Wise!!! Your words mean a lot to me. Now it makes two of us, who even made it working ;-P

      Author's profile photo Douglas Maltby
      Douglas Maltby

      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:

      • Starting a bash shell from within the container using “docker exec -it myorientdb01 bash”.
      • Inspecting the container config using “docker inspect myorientdb01”
      • Listing network ports of the docker image using “docker port myorientedb01”
      • Listing the networks available for docker using “docker network ls”
      • Statistics (like top) of your running containers using “docker stats”

      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

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki
      Blog Post Author

      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

      Author's profile photo Douglas Maltby
      Douglas Maltby

      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!

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki
      Blog Post Author

      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)

      Author's profile photo Douglas Maltby
      Douglas Maltby

      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/

      • "Last but not least, Docker Desktop now includes an interactive Dashboard UI for managing your local running containers and Compose applications. We have been listening to developers and working hard to incorporate a single user interface across Mac and Windows so that we could look at how we can make it easier to work with Docker locally. Historically Docker offered similar capability with Kitematic, which we plan to archive in 2020 and replace with the new Desktop Dashboard."

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki
      Blog Post Author

      Philipp, Douglas: the second part is off the press: https://blogs.sap.com/2019/12/06/understanding-containers-part-02-inside-a-container/

      Author's profile photo Sagar Sheokand
      Sagar Sheokand

      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.

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki
      Blog Post Author

      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?

      Author's profile photo Sagar Sheokand
      Sagar Sheokand

      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.)