Linux and Docker Interview Questions
Table of Contents
Common Linux Interview Topics for Backend Developers
Backend interviews often include Linux questions because most production servers run on some Linux distribution. You do not need to be a system administrator, but you must be comfortable using Linux to run and debug backend applications.
This chapter focuses on the types of Linux and Docker questions you are likely to see and how to think about them, not on teaching Linux or Docker from scratch. For detailed learning, rely on earlier chapters in the course.
Typical Linux Knowledge Areas
Interviewers often probe these areas:
- Navigating the filesystem
- Working with files and directories
- Permissions and users
- Processes and signals
- Networking basics
- System monitoring
- Logs and services
- Environment variables
Below are example questions and short, practical answers.
Navigating and Inspecting the Filesystem
Example questions:
- How do you check which directory you are in?
- How do you list all files, including hidden ones?
- How do you find a file by name?
Key commands and examples:
pwd # print working directory
ls # list files
ls -la # list all files with details, including hidden
cd /var/log # change directory
cd .. # go up one directory
cd ~ # go to home directoryFinding files:
find /var/log -name "nginx*.log"
find . -type f -name "*.py"
Using grep to search inside files:
grep "ERROR" app.log
grep -R "DATABASE_URL" .Table of common commands:
| Task | Command example |
|---|---|
| Show current directory | pwd |
| List files | ls, ls -la |
| Change directory | cd /path/to/dir |
| Find file by name | find . -name "config*.yml" |
| Search text in files | grep -R "secret" . |
Managing Files and Directories
Example questions:
- How do you copy, move, or delete files?
- How do you view the contents of a file?
- How do you create or edit a file from the command line?
Basic operations:
cp a.txt b.txt # copy file
cp -r src/ backup-src/ # copy directory recursively
mv app.log app.log.bak # move or rename
rm file.tmp # remove file
rm -rf build/ # remove directory recursively (dangerous)Viewing files:
cat app.log # print whole file
less app.log # scroll through file
head -n 20 app.log # first 20 lines
tail -n 50 app.log # last 50 lines
tail -f app.log # follow log in real timeEditing quickly with simple editors:
nano config.env
vi app.py
Be very careful with rm -rf. A common rule is: never run rm -rf on a path you have not double checked. A single mistake like rm -rf / can destroy the system.
Permissions and Users
Backend developers often deploy apps to servers where file ownership and permissions control what the app can access.
Example questions:
- How do permissions work in Linux?
- How do you change a file’s permissions or owner?
- How do you check which user you are, and switch users?
Check ownership and permissions:
ls -l app.log
# -rw-r--r-- 1 ubuntu ubuntu 1234 Aug 10 12:34 app.log- The first part
-rw-r--r--shows permissions. - Then owner and group, here both
ubuntu.
Change permissions and ownership:
chmod 640 config.env # change permissions
chown appuser:appuser app.log # change owner and groupUser related:
whoami # current user
id # show user and group info
sudo su - appuser # switch to appuser with login shellTable of numeric permissions:
| Code | Meaning | Typical use |
|---|---|---|
| 644 | rw-r--r-- | normal text files |
| 600 | rw------- | secrets / private keys |
| 755 | rwxr-xr-x | executable scripts, dirs |
| 700 | rwx------ | private executable / dir |
A common security rule: never store secrets (API keys, DB passwords) in world readable files. Use permissions like 600 and limit access to the application user only.
Processes and Services
You must be able to check if your backend is running, see its PID, and stop or restart it.
Example questions:
- How do you see which processes are running?
- How do you find a specific process and kill it?
- How do you restart a service managed by
systemd?
Process related:
ps aux | grep uvicorn
pidof gunicorn
kill 12345 # send SIGTERM
kill -9 12345 # force kill with SIGKILL (use last)Monitoring live processes:
top
htop # nicer, if installed
Services with systemd:
sudo systemctl status myapp.service
sudo systemctl restart myapp.service
sudo systemctl enable myapp.service # start on bootCommon signals:
| Signal | Code | Use |
|---|---|---|
| SIGTERM | 15 | Ask process to exit gracefully |
| SIGINT | 2 | Like Ctrl+C in terminal |
| SIGKILL | 9 | Force kill, no cleanup |
Networking Basics on Linux
Backend debugging often involves ports and connections.
Example questions:
- How do you see which ports are open and which process listens?
- How do you test connectivity to a host and port?
- How do you check DNS resolution?
Check listening ports and processes:
sudo ss -tuln
sudo ss -tulnp | grep 8000 # who listens on port 8000Or in older systems:
sudo netstat -tulnp | grep 8000Connectivity and DNS:
ping example.com
curl http://localhost:8000/health
dig example.com
nslookup example.comTable of common ports:
| Service | Port |
|---|---|
| HTTP | 80 |
| HTTPS | 443 |
| PostgreSQL | 5432 |
| Redis | 6379 |
System Monitoring and Logs
You must know where to look when something is slow or broken.
Example questions:
- How do you check CPU and memory usage?
- How do you view system logs or service logs?
Monitoring:
top # CPU, memory, processes
htop # improved top
free -h # memory usage
df -h # disk usage
du -sh * # disk usage per file/dir in current directoryLogs:
journalctl -u myapp.service # logs for a systemd service
journalctl -u myapp.service -f # follow live
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.logFor production debugging: always check logs first. Service logs, application logs, and system logs usually tell you why something failed.
Environment Variables
Environment variables are a standard way to configure backend services.
Example questions:
- How do you list environment variables?
- How do you set one for a single command?
- How do you make one available to a service?
Examples:
printenv # list variables
echo "$DATABASE_URL"
export DEBUG=false # set in current shell
DATABASE_URL=postgres://... uvicorn app:app
For systemd services, you often configure environment variables in the unit file or an environment file, then reload and restart.
Typical Docker Knowledge Areas
Docker is extremely common in backend development. Interviewers want to know that you can:
- Understand images versus containers
- Build images from a
Dockerfile - Run containers with ports and volumes
- See logs and debug containers
- Use
docker-composeor similar tools
Images vs Containers
Example questions:
- What is the difference between an image and a container?
- How do you list images and containers?
Commands:
docker images # list images
docker ps # running containers
docker ps -a # all containers
docker rm <container> # remove stopped container
docker rmi <image> # remove imageConceptually:
- An image is a snapshot with your app and all dependencies.
- A container is a running instance of an image.
A useful mental rule: image is like a class, container is like an object instance. You build an image once, then run many containers from it.
Running Containers
Example questions:
- How do you run a container and expose a port?
- How do you run a container in the background?
- How do you mount a volume?
Basic run example:
docker run --rm -it python:3.12-slim pythonExposing ports:
docker run -d -p 8000:8000 myapp-image
# host:containerMounting a volume:
docker run -d \
-p 8000:8000 \
-v $(pwd)/logs:/app/logs \
myapp-image
Table of common docker run flags:
| Flag | Meaning |
|---|---|
-d | Run detached in background |
-p a:b | Map host port a to container b |
-v a:b | Mount host path a to b |
--rm | Remove container on exit |
-e | Set environment variable |
Dockerfile Basics
You will often be asked to explain or write a simple Dockerfile.
Example questions:
- How would you containerize a Python web app?
- What does each instruction in this
Dockerfiledo?
Example Dockerfile for a FastAPI app:
FROM python:3.12-slim
WORKDIR /app
ENV PYTHONUNBUFFERED=1
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]Key instructions:
| Instruction | Purpose |
|---|---|
FROM | Base image |
WORKDIR | Set working directory |
ENV | Define environment variable in image |
COPY | Copy files into image |
RUN | Run command at build time |
EXPOSE | Document port the app listens on |
CMD | Default command on docker run |
Common rule: copy and install dependencies first, then copy the rest of the code. This keeps Docker build cache effective, so rebuilds are faster.
Building and Tagging Images
Example questions:
- How do you build an image from a
Dockerfile? - What is a tag and how do you use it?
Basic build:
docker build -t myapp:latest .
docker build -t myapp:1.0.0 .Then run:
docker run -d -p 8000:8000 myapp:1.0.0You might also see questions about pushing to a registry:
docker tag myapp:1.0.0 myuser/myapp:1.0.0
docker push myuser/myapp:1.0.0Inspecting, Logging, and Debugging Containers
Example questions:
- How do you see logs from a container?
- How do you execute a shell inside a running container?
- How do you inspect environment variables or configuration?
View logs:
docker logs myapp-container
docker logs -f myapp-container # follow logsExec into container:
docker exec -it myapp-container /bin/bash
# or
docker exec -it myapp-container /bin/shInspect details:
docker inspect myapp-container
docker inspect myapp-imageTypical debug flow:
docker psto find container.docker logsto see errors.docker exec -itto check files, env vars, network from inside.
docker-compose Basics
Many backends use docker-compose for multi container setups.
Example questions:
- How would you run an app with Postgres using Docker?
- What does this
docker-compose.ymlfile do?
Example docker-compose.yml:
version: "3.9"
services:
db:
image: postgres:16
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: appdb
ports:
- "5432:5432"
volumes:
- db-data:/var/lib/postgresql/data
web:
build: .
environment:
DATABASE_URL: postgresql://app:secret@db:5432/appdb
ports:
- "8000:8000"
depends_on:
- db
volumes:
db-data:Commands:
docker compose up # start all services
docker compose up -d # start in background
docker compose down # stop and remove
docker compose logs web # logs for web serviceHow to Prepare Efficiently
You do not need to memorize every command. Focus on:
- Core Linux skills
- Navigation, file operations, permissions.
- Processes and ports.
- Logs and resource monitoring.
- Core Docker skills
- Understand images vs containers.
- Write and explain a simple
Dockerfile. - Run containers with ports, env vars, and volumes.
- Use basic
docker-compose. - Practice in a real environment
- Spin up a small FastAPI app with Docker.
- Add Postgres with
docker-compose. - Practice checking logs, debugging port issues, and restarting services.
If you can calmly explain how you would:
- Start a backend app in a Docker container
- Connect it to a database
- Check that it is listening on the correct port
- Read logs and fix a misconfiguration
then you are well prepared for most Linux and Docker interview questions at a backend developer level.
Views: 10
KAHIBARO