Skip to Content
Technical Articles

Understanding containers (part 02): inside a container

Thank for all the feedback after the part 01 of this series. I hope you enjoyed as well some exercises with OrientDB database.

Let’s keep digging into containers!

I assume that you have the container myorientdb01 running, e.g. by running it with docker start myorientdb01, if it was stopped in the meantime.

How do I get “into the container”?

I do not know about you, but for me it was the very first question. Used to usual VMs (virtual machines) I was expecting some way to get “inside the container” to work with it.

Quick web search and I found that command to do it, like

docker exec -it myorientdb01 bash

Again, I do not know about you, but for me it was another “Say whaaat??!” moment. “It is not connecting to the container. It is executing a container and calling its OS shell?? And why is IT (as I looked at -it) involved?

But let me calm down and try to understand what’s going on.

The above command is the short version of
docker container exec --tty --interactive myorientdb01 bash,
so basically it tells docker to execute the bash command inside the running container myorientdb01.

Ok, let’s execute that command.

Well, where are we?

Let’s look around what we’ve got here…

…by running a few commands, like whoami, uname -a, cat /etc/os-release, tty and finally exit (or you can press Ctrl+D to exit).

Why -i and -t

Let’s quickly play with these options. First by running the command without -i

docker exec -t myorientdb01 bash

…and typing something like whoami, exit or even What am I doing here?.

Even though we connected to terminal in the container, the input from my keyboard is not sent to the terminal. Obviously Ctrl+D will not work to exit, so I needed Ctrl+C to interrupt.

Now, let’s try executing exec without -t option…

docker exec -i myorientdb01 bash

…and typing commands whoami, tty, exit.

This time commands are received by the container and results are displayed, but there is no terminal assigned (as indicated by not a tty response from the tty command) and no shell prompt.

What is exec for?

Even though I used it to “connect” to the running container, in fact I was just executing bash command in that running container. That gave me that perception of “being in the container”.

But it means I can use exec to execute any command from a container without going “into” the container, like…

docker exec myorientdb01 whoami

and

docker exec --user nobody myorientdb01 whoami

…to see the results. No input or terminal connections were required to execute this commands in the container and get results.

Running client software

So far we tried some basic OS commands in the container that runs the OrientDB server. We used to connect to that server using its web-based Studio via exposed port.

But what if I want to connect to that database using its console client (because I am cool, because I am techie, because I am command line guy, because I try to look geeky, whatever…)?

No need to install that client software, because it is already available in the container in database’s bin directory, so we can call it using docker, like…

docker exec -it myorientdb01 bin/console.sh "create database remote:localhost/mydb root root"

… to create our own mydb database using so-called batch mode of the console.

Now I can open Studio and see that database there…

…to which I can connect using standard user admin with its default password admin. 🙂

Ok, my train is arriving…

…to Kraków. Literally. I will be presenting this topic at the “Career in IT” conference tomorrow. And I won’t have time to work on this more tonight, because tonight we have the first ever local SAP Stammtisch in Kraków, organized by Izabela Rębisz. Na zdrowie 🍻

If you are interested in this topic, but it is too late for you to arrive to Kraków, then I will have the same presentation at SAP Inside Track in Walldorf next month. See you there?


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)

PS. This was my blog post #100 (decimal, not binary ;-)) on SAP Community 🍾

2 Comments
You must be Logged on to comment or reply to a post.