Container
Контейнер
A container is an isolated instance of an application, with its own view of files and dependencies. It uses the operating system kernel it runs on rather than booting a separate one.
What a container gives you
Suppose a web service works on your laptop but fails in CI because the runner has an older library. Packaging the service and its dependencies into a container image lets both machines start from the same set of files. The image is the packaged artifact; a container is an instance created from it. You can start several containers from one image and give each one different settings, such as an environment variable pointing to a test or production database.
What happens on Linux
A container runtime starts the application as one or more Linux processes. It uses namespaces to give those processes a restricted view of resources such as process IDs, mounts, and network interfaces. It can use control groups (cgroups) to track resource usage and apply CPU or memory limits. A virtual machine, by contrast, boots a guest operating system with its own kernel. Linux containers share the kernel of the Linux system where their processes run, even if that system is itself a VM, as with Docker Desktop on macOS.
A typical Docker container sees the image's read-only layers plus its own writable layer. Changes made there don't change the image or other containers created from it. The writable layer survives a stop and restart, but it goes away when the container is removed. Store database files or uploads in a persistent volume or external storage if they need to survive replacement.
Try a local web server
docker run --rm -p 127.0.0.1:8080:80 nginx:alpine
This starts Nginx from the nginx:alpine image. Open http://localhost:8080 to see the welcome page: Docker forwards connections from port 8080 on the host's loopback interface to port 80 in the container. When the container stops, --rm removes the container but leaves the image available for reuse.
Where containers fit in a deployment
A team can test an image in CI and deploy that same artifact to staging and production. This keeps application files and dependency versions consistent, not the whole environment: configuration, secrets, and external services can still differ. Kubernetes runs containers inside Pods and manages those Pods as workloads scale or need replacement.
Interview troubleshooting
A common interview scenario is a container that exits immediately. Check what it was asked to run: a container stops when its main process exits. A successful exit can be normal for a batch job, but for a web service you would check the exit code and logs, then verify that the startup command keeps the server running in the foreground.