A guide to basics of docker
# Mastering Docker: A Step-by-Step Guide
Docker has become an integral part of modern software development, providing a lightweight and efficient way to package, distribute, and run applications. In this guide, we’ll take you through the essential Docker commands to get you started on your containerization journey.
## Installing Docker
Before diving into Docker commands, you need to have Docker installed on your system. Use the following commands to install Docker and Docker Compose on a Linux system:
sudo apt install docker-compose
sudo apt install docker.io
## Pulling Docker Images
Once Docker is installed, you can start by pulling Docker images from the official registry or other repositories. Use the following command to pull an image:
docker pull <image name>
# Example: docker pull nginx
To view a list of downloaded images, use:
docker images
## Running Docker Containers
To run a Docker container, use the following command:
docker run <image name>
# Example: docker run nginx
To find running Docker containers and list them along with their IP addresses, use:
docker ps
To show all Docker containers, including those not currently running, use:
docker ps -a
## Inspecting Docker Containers
If you want to find the IP address of a specific running container, you can use the following command:
docker inspect <container id>
# Example: docker inspect 73704850cdf7
## Deploying at localhost
After running a container, you can access it locally using the specified port. For example:
Assuming the container runs on port 80
http://localhost:80
## Stopping and Restarting Docker Containers
To stop a running container, use:
docker stop <container id>
To restart a previously stopped container, use:
docker start <container id>
## Deleting Docker Containers and Images
To delete a Docker container, use:
docker rm <container id>
To delete a Docker image, use:
docker rmi <image id>
## Running Docker in Detached Mode
If you want to run a Docker container in the background (detach mode), use:
docker run -d nginx
## Changing the Name of a Container
To change the name of a Docker container, use:
docker run — name <new_name> -d <repository name>
Docker simplifies the deployment and management of applications, making it a valuable tool for developers and system administrators. Experiment with these commands to enhance your understanding of Docker and streamline your development workflow.