Containers

  • What is Docker and why use it?
    Docker is a platform for building, running, and sharing containers—lightweight, isolated environments that package an application with its dependencies. It simplifies deployment by ensuring software runs the same way on any machine.
  • How do I write a Dockerfile?
    A Dockerfile is a text file with instructions to build a Docker image. Start with a base image (FROM), copy your code (COPY), install dependencies (RUN), and set the startup command (CMD).
  • What is the difference between a container and a virtual machine?
    Containers share the host OS kernel and isolate processes, while virtual machines run a full guest OS on virtualized hardware. Containers are lighter and faster to start; VMs offer stronger isolation.
  • How do I run a Docker container in the background?
    Use the -d (detached) flag with docker run, e.g., 'docker run -d my-image'. The container runs in the background and prints the container ID.
  • What is Docker Compose?
    Docker Compose is a tool for defining and running multi-container Docker applications. You describe services, networks, and volumes in a YAML file, then start everything with 'docker compose up'.
  • How do I reduce Docker image size?
    Use smaller base images (like Alpine), combine RUN commands, remove unnecessary files, and use multi-stage builds to keep only what's needed in the final image.
  • What are the basics of Kubernetes deployment?
    A Kubernetes Deployment declares how many copies of an app should run and which container image to use. Kubernetes then creates the pods, replaces failed ones and performs rolling updates when you change the image.
  • How do I stop and remove Docker containers?
    List containers with docker ps -a, stop one with docker stop NAME, then remove it with docker rm NAME. Use docker container prune to clear all stopped containers.
  • What is the difference between a Docker image and a container?
    An image is a read-only template holding the app and its dependencies, while a container is a running instance made from that image. One image can run as many containers.
  • Why does my Docker container exit right after it starts?
    A container exits when its main process finishes or crashes, so the cause is usually a command that ends too early or an error at startup. Read the container logs and check the command and entrypoint first.
  • Can I run two containers on one small server?
    Two containers can share one server if each has its own port or sits behind a reverse proxy, and the machine has enough memory and CPU for both. Use a proxy to route traffic to each one by name or path.