-
Pull an image from Docker Hub
docker pull <image_name>
-
List downloaded images
docker images
-
Run a container from an image
docker run <image_name>
-
Run a container in detached mode (background mode)
docker run -d <image_name>
-
View logs of a running container
docker logs <container_id>
-
List running containers
docker ps
-
Stop a running container
docker stop <container_id>
-
Run a container with port mapping
docker run -d -p <host_port>:<container_port> nginx:1.23
-
List all containers (including stopped ones)
docker ps -a
-
Start a stopped container
docker start <container_id>
-
Remove a stopped container
docker rm <container_id>
-
Force remove a running container
docker rm -f <container_id>
-
Run a container with a custom name
docker run --name <container_name> -d -p <host_port>:<container_port> nginx:1.23
- Registry: A storage and distribution system for Docker images (e.g., Docker Hub, AWS ECR, Google Container Registry).
- Repository: A collection of related Docker images with different tags (e.g.,
nginx:1.21
,nginx:1.23
in thenginx
repository).
A Dockerfile is a script containing a series of instructions on how to build a Docker image.
# Base image
FROM <base_image>
# Run a command during build
RUN <command>
# Copy a file into the container
COPY <file_name> /<target_directory>/
# Set working directory inside the container
WORKDIR /<directory>
# Default command to run when container starts
CMD ["node", "server.js"]
- Build an image using a Dockerfile
docker build -t node-app:1.0 .
-t node-app:1.0
→ Assigns a name (node-app
) and tag (1.0
)..
→ Specifies the location of the Dockerfile (current directory).
This note serves as a quick reference for learning and using Docker efficiently.