March 11, 2017
I’m currently looking for a job and I found a weird pattern about Docker questions. Once I confirmed I had worked with Docker, no more questions were asked… Lucky me you may think, but that made me wonder why is that. Working with Docker is failry easy. Docker simplified the process of working with isolated resources providing a high-level API to run processes in isolation, but does it not deserve to a little chat about it during an interview? …I will let you know if “be careful what you wish for” will utter the loud in my head on my next interview :)
Be pragmatic. I used to interview people when was recruiting to my team and I’ve never been a fan of pure theoretical quesions. This is not a school, you want people who either worked on a similar project or are smart enough to handle similar issues you face in your project. Ok, here’s a list of questions about Docker I would asked myself on an interview:
What is the difference between ‘docker run’ and ‘docker create’?
The primary difference is that using ‘docker create’ creates a container in a stopped state.
Bonus point: You can use ‘docker create’ and store an outputed container ID for later use. The best way to do it is to use ‘docker run’ with --cidfile FILE_NAME as running it again won’t allow to overwrite the file. A good practice is to keep well ogranised directory structure: /containers/web/server1/ws.cid containers/web/server3/ws.cid
Can you create containers wihout their own PID namespace?
Does the order of starting containers is important, if yes why?
Of course. Let’s say you have linked containers, so there’s a dependency between them.
How to build envrionment-agnostic systems with Docker?
There are three main features helping to achieve that:
- Environment variable injection
- Read-only file systems
What are the four states that a Docker container can be in?
A more tricky version of this question:
Which of the four states is used if the container container has never been started?
The answer is: Exited …but not sure if it’s worth to ask it :)
Can you remove (‘docker rm’) a container that is paused?
No, to remove a container it must be stopped first.
Does a Docker container automatically restart itself?
No. The default –restart flag is set to never restart.
Which way of removing containters is preffered, ‘docker rm -f’ or docker stop followed by docker rm?
‘docker stop’ is preffered as it will send a SIG_HUP signal to its recipients giving them time to perform finalization and cleanup tasks.
When would you use ‘docker kill’ or ‘docker rm -f’?
If you must stop the container really quickly… (someone pushed something to production on Friday evening?… ;) )
Where are Docker images stored when your do ‘docker pull’ ?
(I would ask this question only to find out if someone was curious enough to check it).
Since I’m a linux user, I can tell only about Linux (and I mean Linux …not OSX).
Saying /var/lib/docker is ok as subdirectories may differ based on Docker version.
Bonus point: running ‘docker inspect NAME|ID’ rerurns such info
What’s the difference between a repository and a registry?
Docker registry is a service for hosting and distributing images (the default one is the Docker Hub). Docker repository is a collection of related Docker images (the same name but with different tags).
How to link containers?
The simplest way is to use network port mapping. There’s also the - -link flag which is deprecated.
What happens to a data volume after a container is deleted?
What is an orphant volume and how to remove it?
An orphant volume is a volume without any containers attached to it. Prior Docker v. 1.9 it was very problematic to remove it.
When you limit the memory for a container, does it reserve (guarantee) the memory?
No, it only protects from overconsumption.
What is the default CPU limit set for a container?
No limit by default, it can consume up to 100% of the CPU.
Does Docker support User Namespaces?
Yes, you can map the root user in a container to a non uid-0 user outside then container (it is not enabled by default).
What is the difference between Docker RUN, CMD and ENTRYPOINT?
CMD does not execute anything at build time, but specifies the intended command for the image.
RUN actually runs a command and commits the result.
If you would like your container to run the same executable every time, then you should consider using ENTRYPOINT in combination with CMD.
Why did Docker jump from version 1.13 to 17.03?
I would ask this only to see if someone is following updates. Starting with version 17.03 Docker is on a monthly release cycle and uses a new YY.MM versioning scheme to reflect this.
Which instruction must be given first in a Dockerfile?
Do instructions in Dockerfile are case-sensitive?
No. However, convention is for them to be uppercase (to distinguish them from arguments more easily).
What happens if you add more than one CMD instruction to a Dockerfile?
Only the last CMD will take effect.
Can you run Docker containers natively on Windows?
With Windows Server 2016 you can run Docker containers natively on Windows, and with Windows Nano Server you’ll have a lightweight OS to run inside containers, so you can run .NET apps on their native platform.
What are you salary expectations?
Ok, it’s a question for another post ;)
Apart increasing your chances to pass an interview, listing such questions is another form of presenting a topic in Q&A which I find very useful.