KAHIBARO
Discord Login Register

Linux and Docker Interview Questions

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:

Below are example questions and short, practical answers.

Navigating and Inspecting the Filesystem

Example questions:

Key commands and examples:

bash
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 directory

Finding files:

bash
find /var/log -name "nginx*.log"
find . -type f -name "*.py"

Using grep to search inside files:

bash
grep "ERROR" app.log
grep -R "DATABASE_URL" .

Table of common commands:

TaskCommand example
Show current directorypwd
List filesls, ls -la
Change directorycd /path/to/dir
Find file by namefind . -name "config*.yml"
Search text in filesgrep -R "secret" .

Managing Files and Directories

Example questions:

Basic operations:

bash
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:

bash
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 time

Editing quickly with simple editors:

bash
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:

Check ownership and permissions:

bash
ls -l app.log
# -rw-r--r-- 1 ubuntu ubuntu 1234 Aug 10 12:34 app.log

Change permissions and ownership:

bash
chmod 640 config.env          # change permissions
chown appuser:appuser app.log # change owner and group

User related:

bash
whoami                        # current user
id                            # show user and group info
sudo su - appuser             # switch to appuser with login shell

Table of numeric permissions:

CodeMeaningTypical use
644rw-r--r--normal text files
600rw-------secrets / private keys
755rwxr-xr-xexecutable scripts, dirs
700rwx------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:

Process related:

bash
ps aux | grep uvicorn
pidof gunicorn
kill 12345        # send SIGTERM
kill -9 12345     # force kill with SIGKILL (use last)

Monitoring live processes:

bash
top
htop             # nicer, if installed

Services with systemd:

bash
sudo systemctl status myapp.service
sudo systemctl restart myapp.service
sudo systemctl enable myapp.service   # start on boot

Common signals:

SignalCodeUse
SIGTERM15Ask process to exit gracefully
SIGINT2Like Ctrl+C in terminal
SIGKILL9Force kill, no cleanup

Networking Basics on Linux

Backend debugging often involves ports and connections.

Example questions:

Check listening ports and processes:

bash
sudo ss -tuln
sudo ss -tulnp | grep 8000   # who listens on port 8000

Or in older systems:

bash
sudo netstat -tulnp | grep 8000

Connectivity and DNS:

bash
ping example.com
curl http://localhost:8000/health
dig example.com
nslookup example.com

Table of common ports:

ServicePort
HTTP80
HTTPS443
PostgreSQL5432
Redis6379

System Monitoring and Logs

You must know where to look when something is slow or broken.

Example questions:

Monitoring:

bash
top        # CPU, memory, processes
htop       # improved top
free -h    # memory usage
df -h      # disk usage
du -sh *   # disk usage per file/dir in current directory

Logs:

bash
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.log

For 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:

Examples:

bash
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:

Images vs Containers

Example questions:

Commands:

bash
docker images             # list images
docker ps                 # running containers
docker ps -a              # all containers
docker rm <container>     # remove stopped container
docker rmi <image>        # remove image

Conceptually:

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:

Basic run example:

bash
docker run --rm -it python:3.12-slim python

Exposing ports:

bash
docker run -d -p 8000:8000 myapp-image
# host:container

Mounting a volume:

bash
docker run -d \
  -p 8000:8000 \
  -v $(pwd)/logs:/app/logs \
  myapp-image

Table of common docker run flags:

FlagMeaning
-dRun detached in background
-p a:bMap host port a to container b
-v a:bMount host path a to b
--rmRemove container on exit
-eSet environment variable

Dockerfile Basics

You will often be asked to explain or write a simple Dockerfile.

Example questions:

Example Dockerfile for a FastAPI app:

dockerfile
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:

InstructionPurpose
FROMBase image
WORKDIRSet working directory
ENVDefine environment variable in image
COPYCopy files into image
RUNRun command at build time
EXPOSEDocument port the app listens on
CMDDefault 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:

Basic build:

bash
docker build -t myapp:latest .
docker build -t myapp:1.0.0 .

Then run:

bash
docker run -d -p 8000:8000 myapp:1.0.0

You might also see questions about pushing to a registry:

bash
docker tag myapp:1.0.0 myuser/myapp:1.0.0
docker push myuser/myapp:1.0.0

Inspecting, Logging, and Debugging Containers

Example questions:

View logs:

bash
docker logs myapp-container
docker logs -f myapp-container   # follow logs

Exec into container:

bash
docker exec -it myapp-container /bin/bash
# or
docker exec -it myapp-container /bin/sh

Inspect details:

bash
docker inspect myapp-container
docker inspect myapp-image

Typical debug flow:

  1. docker ps to find container.
  2. docker logs to see errors.
  3. docker exec -it to check files, env vars, network from inside.

docker-compose Basics

Many backends use docker-compose for multi container setups.

Example questions:

Example docker-compose.yml:

yaml
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:

bash
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 service

How to Prepare Efficiently

You do not need to memorize every command. Focus on:

  1. Core Linux skills
    • Navigation, file operations, permissions.
    • Processes and ports.
    • Logs and resource monitoring.
  2. 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.
  3. 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:

then you are well prepared for most Linux and Docker interview questions at a backend developer level.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!