Asosiy matnga o'tish
ITIT Interview
Docker

Cheatsheet

Barcha asosiy Docker va Docker Compose buyruqlari bitta sahifada. Intervyudan oldin tez takrorlash uchun.

Konteynerlar

BuyruqVazifasi
docker run -d --name web -p 8080:80 nginxKonteyner ishga tushirish
docker run -it --rm ubuntu bashInteraktiv, chiqqanda o'chiriladi
docker ps / docker ps -aIshlayotgan / barcha konteynerlar
docker stop web / docker start webTo'xtatish / ishga tushirish
docker restart webQayta ishga tushirish
docker rm web / docker rm -f webO'chirish / majburan o'chirish
docker logs -f --tail 100 webLog'larni kuzatish
docker exec -it web shKonteyner ichida shell
docker inspect webTo'liq ma'lumot
docker statsResurs sarfi
docker cp web:/app/file.txt .Fayl nusxalash

Image'lar

BuyruqVazifasi
docker build -t app:1.0 .Image yasash
docker build --no-cache -t app:1.0 .Keshsiz yasash
docker imagesLokal image'lar
docker pull node:22-alpineRegistry'dan yuklash
docker tag app:1.0 ghcr.io/org/app:1.0Yangi teg berish
docker push ghcr.io/org/app:1.0Registry'ga yuklash
docker history app:1.0Qatlamlar va hajmi
docker rmi app:1.0Image o'chirish
docker buildx build --platform linux/amd64,linux/arm64 .Ko'p platformali build

Volume va tarmoq

BuyruqVazifasi
docker volume create dataVolume yaratish
docker volume ls / docker volume inspect dataRo'yxat / ma'lumot
docker run -v data:/var/lib/data ...Named volume ulash
docker run -v ./src:/app/src ...Bind mount
docker network create appnetTarmoq yaratish
docker run --network appnet ...Tarmoqqa ulash
docker network inspect appnetTarmoq ma'lumoti

Docker Compose

BuyruqVazifasi
docker compose up -dHammasini fonda ko'tarish
docker compose up -d --buildImage'larni qayta yig'ib ko'tarish
docker compose psServislar holati
docker compose logs -f apiServis log'lari
docker compose exec api shServis ichida shell
docker compose run --rm api npm testBir martalik buyruq
docker compose downTo'xtatish va o'chirish
docker compose down -vVolume'lar bilan birga (ma'lumot o'chadi)

Tozalash

BuyruqVazifasi
docker system dfDisk sarfi
docker container pruneTo'xtagan konteynerlar
docker image pruneTeglanmagan image'lar
docker image prune -aIshlatilmayotgan barcha image'lar
docker system pruneIshlatilmayotgan hamma narsa (volume'lardan tashqari)
docker system prune -a --volumesHammasi, volume'lar bilan (ehtiyot bo'ling)

Dockerfile shabloni

Dockerfile
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=build /app/dist ./dist
USER node
EXPOSE 3000
HEALTHCHECK CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "dist/server.js"]

Ushbu sahifada