You are on page 1of 2

How to use Docker

​ Installation:
● Install Docker Desktop (for Windows or macOS) or Docker Engine (for
Linux) from the official Docker website:
https://www.docker.com/products/docker-desktop
​ Docker Basics:
● Image: An image is a lightweight, standalone, executable software
package that includes everything needed to run a piece of software.
● Container: A container is a runtime instance of an image, isolated from the
host system and other containers.
● Dockerfile: A Dockerfile is a script that defines how to build a Docker
image. It includes instructions to copy files, set environment variables, and
more.
​ Docker Commands:
● Open a terminal or command prompt to use Docker commands.
● docker --version: Check the Docker version.
● docker info: Display detailed information about Docker and its
components.
● docker run: Create and start a new container from an image.
● docker ps: List running containers.
● docker images: List available images.
● docker build: Build an image from a Dockerfile.
● docker stop: Stop a running container.
● docker rm: Remove a container.
● docker rmi: Remove an image.
​ Create and Run a Simple Container:
● Pull an image from Docker Hub (a registry of Docker images): docker
pull nginx
● Run a container from the pulled image: docker run -d -p 80:80 nginx
● Open a web browser and visit http://localhost to see the default Nginx
page.
​ Build and Run Your Own Image:
● Create a directory containing your application files.
● Create a Dockerfile in that directory to define how the image should be
built.
● Build the image: docker build -t my-app .
● Run a container using the built image: docker run -d -p 8080:80
my-app
● Access your application in a web browser at http://localhost:8080.
​ Container Management:
● Use docker ps to list running containers and get their IDs.
● Use docker stop <container_id> to stop a container.
● Use docker rm <container_id> to remove a stopped container.
​ Cleaning Up:
● Remove stopped containers: docker container prune
● Remove unused images: docker image prune
​ Compose and Orchestrate:
● For more complex applications with multiple services, you can use Docker
Compose to define and run multi-container applications.
● For orchestration and managing containers in production, consider tools
like Kubernetes.

Remember that this is just a basic introduction to using Docker. There are many
advanced features and use cases that you can explore, including creating custom
networks, volume mounts, working with Docker registries, and more. It's recommended
to delve into the official Docker documentation and tutorials to gain a deeper
understanding of Docker's capabilities.

You might also like