Docker
Introduction
Docker is a platform for developing, shipping, and running applications inside lightweight, portable containers. It enables developers to package applications with all dependencies and run them in any environment.
Installation
Follow the guide on the official Docker website .
Basic Commands
Check Docker Version
docker --versionRunning a Container
docker run -d -p 80:80 nginxListing Running Containers
docker psStopping a Container
docker stop <container_id>Removing a Container
docker rm <container_id>Listing Images
docker imagesRemoving an Image
docker rmi <image_id>Dockerfile
A Dockerfile is a script containing a series of instructions on how to build a Docker image.
Example Dockerfile
Dockerfile
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]Building an Image
docker build -t myapp .Running a Container from an Image
docker run -p 3000:3000 myappDocker Compose
Docker Compose allows managing multi-container applications using a YAML file.
Example docker-compose.yml
version: "3"
services:
web:
image: nginx
ports:
- "80:80"
db:
image: postgres
environment:
POSTGRES_PASSWORD: exampleRunning Docker Compose
docker-compose up -dStopping Docker Compose
docker-compose downNetworking in Docker
Listing Networks
docker network lsCreating a Network
docker network create mynetworkConnecting a Container to a Network
docker network connect mynetwork mycontainerVolumes in Docker
Creating a Volume
docker volume create myvolumeListing Volumes
docker volume lsUsing a Volume in a Container
docker run -v myvolume:/data busyboxLast updated on