Engineering Tools for AI

प्रोग्रामिंग

Docker

Docker images, containers, Dockerfile, Compose, ports, volumes, logs और common troubleshooting की searchable guide।

33 items

मुख्य अवधारणाएँ

Docker

Docker

docker --version

अर्थ

A tool for packaging and running applications in isolated containers.

कब उपयोग करें

Use it when you want the app to run with the same OS packages, runtime, and dependencies across machines.

उदाहरण

docker --version

अनुरोध उदाहरण

Explain whether this project can be run with Docker.

मुख्य अवधारणाएँ

Docker daemon

Docker daemon

Cannot connect to the Docker daemon

अर्थ

The background service that builds images and runs containers.

कब उपयोग करें

If Docker commands cannot connect, Docker Desktop or the Docker service may not be running.

उदाहरण

Cannot connect to the Docker daemon

अनुरोध उदाहरण

Check why Docker commands cannot connect to the daemon.

मुख्य अवधारणाएँ

Image

Image

node:20-alpine

अर्थ

A reusable template used to create containers.

कब उपयोग करें

Images define what OS, runtime, libraries, and app files a container starts with.

उदाहरण

node:20-alpine

अनुरोध उदाहरण

Tell me which base image this Dockerfile uses.

मुख्य अवधारणाएँ

Container

Container

docker ps

अर्थ

A running or stopped instance created from an image.

कब उपयोग करें

Use containers to run the app, database, cache, or worker in isolated environments.

उदाहरण

docker ps

अनुरोध उदाहरण

List running containers and explain what each one does.

मुख्य अवधारणाएँ

Registry

Registry

docker pull postgres:16

अर्थ

A server where Docker images are stored and downloaded from.

कब उपयोग करें

Docker Hub and private registries are used to share base images or deployable app images.

उदाहरण

docker pull postgres:16

अनुरोध उदाहरण

Explain where this image will be downloaded from.

Dockerfile

Dockerfile

Dockerfile

Dockerfile

अर्थ

A file that defines how to build a Docker image.

कब उपयोग करें

Use it to install dependencies, copy app files, and define the command that starts the app.

उदाहरण

Dockerfile

अनुरोध उदाहरण

Read this Dockerfile and summarize the build steps.

Dockerfile

FROM

FROM

FROM node:20-alpine

अर्थ

The Dockerfile instruction that chooses the base image.

कब उपयोग करें

It decides the starting OS layer and often the runtime version.

सावधानी

Changing the base image can affect available commands, security updates, and image size.

उदाहरण

FROM node:20-alpine

अनुरोध उदाहरण

Explain what this FROM image includes.

Dockerfile

WORKDIR

WORKDIR

WORKDIR /app

अर्थ

Sets the folder inside the image where following commands run.

कब उपयोग करें

Use it so COPY, RUN, and CMD commands operate from a predictable app folder.

उदाहरण

WORKDIR /app

अनुरोध उदाहरण

Explain which folder this Dockerfile uses as the app directory.

Dockerfile

COPY

COPY

COPY package.json package-lock.json ./

अर्थ

Copies files from the build context into the image.

कब उपयोग करें

Use it to add dependency files, source code, and static assets to the image.

उदाहरण

COPY package.json package-lock.json ./

अनुरोध उदाहरण

Tell me which files this COPY step adds to the image.

Dockerfile

RUN

RUN

RUN npm ci

अर्थ

Runs a command while building the image.

कब उपयोग करें

Use it to install OS packages, install dependencies, or build app files.

सावधानी

RUN happens at image build time, not when the container starts.

उदाहरण

RUN npm ci

अनुरोध उदाहरण

Separate Dockerfile build-time commands from container startup commands.

Dockerfile

CMD

CMD

CMD ["npm", "run", "start"]

अर्थ

Defines the default command that runs when the container starts.

कब उपयोग करें

Use it to start the web server, API server, worker, or script.

उदाहरण

CMD ["npm", "run", "start"]

अनुरोध उदाहरण

Tell me what command this container starts with.

Dockerfile

EXPOSE

EXPOSE

EXPOSE 3000

अर्थ

Documents which port the containerized app is expected to listen on.

कब उपयोग करें

Use it as a hint, then publish the port with docker run -p or compose ports.

सावधानी

EXPOSE alone does not make the app reachable from your browser.

उदाहरण

EXPOSE 3000

अनुरोध उदाहरण

Explain whether this exposed port is actually published.

Dockerfile

.dockerignore

.dockerignore

node_modules

अर्थ

A file that excludes paths from the Docker build context.

कब उपयोग करें

Use it to keep local dependencies, build output, secrets, and temporary files out of the image build.

उदाहरण

node_modules

अनुरोध उदाहरण

Check whether this .dockerignore excludes unsafe or unnecessary files.

Dockerfile

Build context

Build context

docker build -t my-app .

अर्थ

The folder sent to Docker during image build.

कब उपयोग करें

The final dot in docker build usually means the current folder is the build context.

सावधानी

A large context slows builds and can accidentally include private files.

उदाहरण

docker build -t my-app .

अनुरोध उदाहरण

Explain what files are available to this Docker build.

Docker Compose

Docker Compose

Docker Compose

docker compose up

अर्थ

A tool for running multiple Docker services from one YAML file.

कब उपयोग करें

Use it for app plus database, cache, worker, or local development stacks.

उदाहरण

docker compose up

अनुरोध उदाहरण

Explain what services this compose file starts.

Docker Compose

services

services

services: web: db:

अर्थ

Named app parts defined in a compose file.

कब उपयोग करें

A web service might run the app while a db service runs PostgreSQL.

उदाहरण

services: web: db:

अनुरोध उदाहरण

List the services in this compose file and what each does.

Docker Compose

docker compose up

docker compose up

docker compose up -d

अर्थ

Starts the services defined in a compose file.

कब उपयोग करें

Use -d when you want services to run in the background.

उदाहरण

docker compose up -d

अनुरोध उदाहरण

Start the compose services and show which ones are running.

Docker Compose

docker compose down

docker compose down

docker compose down

अर्थ

Stops and removes containers created by compose.

कब उपयोग करें

Use it when you are done with a local development stack.

सावधानी

Named volumes usually remain unless you explicitly remove volumes.

उदाहरण

docker compose down

अनुरोध उदाहरण

Stop this compose stack without deleting persistent data.

कमांड

docker build

docker build

docker build -t my-app .

अर्थ

Builds a Docker image from a Dockerfile and context.

कब उपयोग करें

Use it after writing a Dockerfile or changing app dependencies.

उदाहरण

docker build -t my-app .

अनुरोध उदाहरण

Build this Docker image and summarize any build errors.

कमांड

docker run

docker run

docker run --name my-app -p 3000:3000 my-app

अर्थ

Creates and starts a container from an image.

कब उपयोग करें

Use it when you want to start one container directly without compose.

उदाहरण

docker run --name my-app -p 3000:3000 my-app

अनुरोध उदाहरण

Run this image and explain the browser URL.

कमांड

docker ps

docker ps

docker ps

अर्थ

Lists running containers.

कब उपयोग करें

Use docker ps -a when you also want stopped containers.

उदाहरण

docker ps

अनुरोध उदाहरण

Show running containers and their published ports.

कमांड

docker stop

docker stop

docker stop my-app

अर्थ

Stops a running container.

कब उपयोग करें

Use it before removing a container or freeing a port.

उदाहरण

docker stop my-app

अनुरोध उदाहरण

Stop the container using port 3000.

कमांड

docker logs

docker logs

docker logs my-app

अर्थ

Prints logs from a container.

कब उपयोग करें

Use it when a container exits, crashes, or the app does not respond.

उदाहरण

docker logs my-app

अनुरोध उदाहरण

Read this container's logs and find the first error.

कमांड

docker exec

docker exec

docker exec -it my-app sh

अर्थ

Runs a command inside an already running container.

कब उपयोग करें

Use it to inspect files, environment variables, or installed tools inside a container.

सावधानी

Changes made manually inside a container can disappear when the container is recreated.

उदाहरण

docker exec -it my-app sh

अनुरोध उदाहरण

Open a shell in this container and check its environment variables.

पोर्ट और नेटवर्क

ports

ports

3000:3000

अर्थ

Maps a port on your machine to a port inside the container.

कब उपयोग करें

Use it so a browser can reach a web app running inside a container.

सावधानी

The left side is the host port, and the right side is the container port.

उदाहरण

3000:3000

अनुरोध उदाहरण

Explain which URL I should open for this ports setting.

पोर्ट और नेटवर्क

localhost in Docker

localhost in Docker

host.docker.internal

अर्थ

localhost can mean the container itself, not your host machine, when code runs inside Docker.

कब उपयोग करें

Use service names in compose networks, or host.docker.internal when a container must reach the host machine.

उदाहरण

host.docker.internal

अनुरोध उदाहरण

Explain why localhost does not reach the database from this container.

फ़ाइल और डेटा

Volume

Volume

db-data:/var/lib/postgresql/data

अर्थ

Docker-managed storage that can persist data outside a container's lifecycle.

कब उपयोग करें

Use volumes for database data or other files that should survive container recreation.

सावधानी

Removing volumes can delete persistent data.

उदाहरण

db-data:/var/lib/postgresql/data

अनुरोध उदाहरण

Tell me which compose volumes store persistent data.

फ़ाइल और डेटा

Bind mount

Bind mount

./src:/app/src

अर्थ

Connects a host folder directly into a container path.

कब उपयोग करें

Use it during development so code edits on the host appear inside the container.

सावधानी

A bind mount can hide files that were copied into the image at the same path.

उदाहरण

./src:/app/src

अनुरोध उदाहरण

Explain whether this volume is a named volume or a bind mount.

फ़ाइल और डेटा

environment

environment

DATABASE_URL=postgres://db:5432/app

अर्थ

Configuration values passed into a container.

कब उपयोग करें

Use environment variables for database URLs, ports, modes, feature flags, and runtime settings.

सावधानी

Do not bake secrets into public images or commit real secret values.

उदाहरण

DATABASE_URL=postgres://db:5432/app

अनुरोध उदाहरण

Check which environment variables this container needs.

समस्या समाधान

port is already allocated

port is already allocated

Bind for 0.0.0.0:3000 failed: port is already allocated

अर्थ

Docker cannot publish a host port because another process or container is already using it.

कब उपयोग करें

Find the process or container using the port, then stop it or choose a different host port.

उदाहरण

Bind for 0.0.0.0:3000 failed: port is already allocated

अनुरोध उदाहरण

Find what is using this Docker port and suggest a safe fix.

समस्या समाधान

container name is already in use

container name is already in use

Conflict. The container name "/my-app" is already in use

अर्थ

A container with the same name already exists.

कब उपयोग करें

List existing containers, then reuse, remove, or rename the old container.

उदाहरण

Conflict. The container name "/my-app" is already in use

अनुरोध उदाहरण

Resolve this container name conflict without deleting data unexpectedly.

समस्या समाधान

Build cache

Build cache

docker build --no-cache -t my-app .

अर्थ

Docker can reuse previous build layers to make builds faster.

कब उपयोग करें

If a change seems ignored, inspect the Dockerfile order or rebuild without cache as a diagnostic step.

सावधानी

--no-cache can make builds slower, so use it intentionally.

उदाहरण

docker build --no-cache -t my-app .

अनुरोध उदाहरण

Explain whether Docker build cache could be hiding my change.

सुरक्षा

docker system prune

docker system prune

docker system prune

अर्थ

Removes unused Docker data such as stopped containers, unused networks, and dangling images.

कब उपयोग करें

Use it when Docker uses too much disk space and you understand what will be removed.

सावधानी

With extra flags, prune can delete images or volumes you still care about.

उदाहरण

docker system prune

अनुरोध उदाहरण

Before pruning Docker, show what would be removed and what data is safe.