Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Vitaliy-R
Developer Advocate
Developer Advocate
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)
11 Comments