# 🐋Docker Commands

In this article, you will see some commands I explored while learning the Docker.

1. **<mark>docker --version</mark>** - Displays the installed docker version.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725204724068/a9cbbc94-41a7-4372-96ff-9858b1ea53f9.png align="left")

2. **<mark>docker image ls </mark>** \- lists all the docker images that you have created on your local machine.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725204151411/6e67e80d-c18f-4ec5-8af4-3faf206fd36f.png align="center")

3. **<mark>docker ps</mark>** - list the running containers
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725204968822/7ed18564-af21-4caf-b0be-ab0d9529e216.png align="center")

4. **<mark>docker ps -a</mark>** - The command ps -a lists every Docker container on your system, including those that are stopped and those that are running.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725206261598/1c71d3aa-e12a-475c-a1b4-6efab8e92c85.png align="center")

5. **<mark>docker run &lt;image_id&gt;</mark>** - A container from a specified Docker image can be created and started using the docker run &lt;image\_id&gt; command.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725205212117/f6e78c78-5c28-4e85-b0ee-9015f3b1f5f3.png align="center")

6. **<mark>docker run -d -p 3000:3000 &lt;image_id&gt;</mark> -** By doing this, a container from the image with ID 2b6e66a71566, would be launched in the background and its port 3000 would be reachable via the host's port 3000.
    

`-d`: Run the container in detached mode (in the background).

`-p <host_port>:<container_port>`: Map a port from the host to the container (e.g., `-p 8080:80`).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725205556345/c3f2719c-00eb-43db-9c60-4d2bcc252440.png align="center")

7. **<mark>docker stop &lt;container_name_or_id&gt;</mark>** - command is used to gracefully stop a running Docker container. You can refer to the container by its name or its container ID.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725206065820/f183c0d4-3516-4fe4-b333-18cd99920509.png align="left")

8. **<mark>docker rm &lt;container_name_or_id&gt;</mark> -** command is used to remove a stopped Docker container. You can specify the container by its name or container ID.
    
9. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725252256268/c7003356-6946-4909-a2d0-24b8e495c385.png align="center")
    
    **<mark>docker build -t mywebapp:01 .</mark>** - This command builds a Docker image from a Dockerfile.
    
    This command will:
    
    * Search for a `Dockerfile` in the current directory.
        
    * Build the image according to the instructions in the Dockerfile.
        
    * `-t` -Tag the resulting image `mywebapp` with the version `01`.
        
    * <mark>.</mark> : The period at the end of the command specifies that the Dockerfile is in the current directory. If your Dockerfile is in another directory, you would specify the path instead of the period.
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725252647265/0f913573-110a-4561-9fad-182f5119ee02.png align="center")
    
10. **<mark>docker push&lt;repository:tag&gt; </mark> \-** Pushes a Docker image to a Docker registry (e.g., Docker Hub).
    
11. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725253502532/5a1de48c-443c-49dc-819a-a9786c5ce24c.png align="center")
    
    **<mark>docker run python:latest </mark>** \-This command is used to create and start a container from the official Python image with the `latest` tag. Which usually means the most recent stable version of Python.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1725253741592/f3000c46-ef0f-4bf6-b117-f64440885294.png align="center")
