Engineering Tools for AI

Программирование

Docker

Справочник по Docker images, containers, Dockerfile, Compose, ports, volumes, logs и частым проблемам.

33 пунктов

Основные понятия

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.