Welcome to the world of Docker! If you're here, you're probably eager to understand and start using Docker, a popular tool for automated deployment, scaling, and orchestration of applications using containerization. Docker allows you to package an application along with all its dependencies and run it consistently across various environments. Let's dive into the basic Docker commands to help you get started.

Before we start, ensure Docker is installed on your system. You can download it from the official Docker website. Once installed, you can verify it by running the command:

Docker Basics
Now that Docker is set up, let's explore some basic commands to interact with Docker.

Running Docker
To start Docker, use the following command in your terminal:

docker --version
This command will output the Docker version installed on your system, verifying that Docker is running.
Creating and Managing Docker Images
Docker images are the building blocks of Docker, functioning as a read-only template for creating containers. To manage Docker images, use these commands:

- List all Docker images:
docker images - Pull a Docker image from Docker Hub:
docker pull [IMAGE_NAME]:[TAG] - Build a Docker image from a Dockerfile:
docker build -t [IMAGE_NAME]:[TAG] . - Remove a Docker image:
docker rmi [IMAGE_ID|IMAGE_NAME]:[TAG]
Working with Docker Containers
Docker containers are instances of Docker images, running as separate processes. They allow you to package, deploy, and run applications in isolated environments.

Creating and Managing Docker Containers
Use the following commands to manage Docker containers:


















- List all Docker containers:
docker ps -a - Run a Docker container in the background:
docker run -d [IMAGE_NAME]:[TAG] - Run a Docker container in the foreground:
docker run [IMAGE_NAME]:[TAG] - Stop a Docker container:
docker stop [CONTAINER_ID|CONTAINER_NAME] - Remove a Docker container:
docker rm [CONTAINER_ID|CONTAINER_NAME]
Viewing and Accessing Docker Containers
To view and access running Docker containers, use these commands:
View the logs of a container:docker logs [CONTAINER_ID|CONTAINER_NAME]
Execute a command in a running container:docker exec [CONTAINER_ID|CONTAINER_NAME] [COMMAND]
Access the shell of a running container:docker exec -it [CONTAINER_ID|CONTAINER_NAME] /bin/bash
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to configure the services of your application. To get started, create a docker-compose.yml file in your project directory and define your services:
Example of a simple docker-compose.yml file:
```yaml version: '3' services: web: image: nginx:latest ports: - "80:80" db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress ```
To run your application using Docker Compose, use the following commands:
- Start and bring up services:
docker-compose up - Stop and remove containers:
docker-compose down
Now that you've explored the basic Docker commands, you're well on your way to harnessing the power of containerization. Happy Docker-ing!