# Docker

## What's Docker ?

Docker is a versatile and powerful platform that simplifies and streamlines the process of building, packaging, and deploying applications. It is based on containerization technology, which allows developers to package an application and all its dependencies into a single, self-contained unit called a container. These containers are highly portable and can run consistently across different environments, such as development, testing, and production, without any compatibility issues. Docker provides a standardized way to develop, ship, and run applications, making it an essential tool for modern software development. It offers benefits like isolation, scalability, and ease of deployment, making it a key component in the world of containerized applications.

{% hint style="info" %}
Installation of Docker engine [here](https://docs.docker.com/engine/install/).
{% endhint %}

## Managing Docker

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker --version
</code></pre></td><td>Check Docker version</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker info
</code></pre></td><td>Display system-wide information about Docker</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker login
</code></pre></td><td>Log in to a Docker registry</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker logout
</code></pre></td><td>Log out from a Docker registry</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker system df
</code></pre></td><td>Show Docker disk usage</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker system prune
</code></pre></td><td>Remove all unused data (images, containers, etc.)</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker pull 
</code></pre></td><td>Pull a Docker image from a registry</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker push 
</code></pre></td><td>Push a Docker image to a registry</td></tr></tbody></table>

### Managing Images

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker images
</code></pre></td><td>List locally available Docker images</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker rmi 
</code></pre></td><td>Remove a Docker image</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker search 
</code></pre></td><td>Search for a Docker image on Docker Hub</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker build -t  
</code></pre></td><td>Build a Docker image from a Dockerfile</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker history 
</code></pre></td><td>Show the history of an image</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image prune
</code></pre></td><td>Remove all dangling images</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image ls
</code></pre></td><td>List Docker images</td></tr></tbody></table>

### Managing Containers

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker ps
</code></pre></td><td>List running containers</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker ps -a
</code></pre></td><td>List all containers, including stopped ones</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker create 
</code></pre></td><td>Create a new container from an image</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker run 
</code></pre></td><td>Create and start a new container from an image</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker run -d 
</code></pre></td><td>Create and start a container in detached mode</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker stop 
</code></pre></td><td>Stop a running container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker start 
</code></pre></td><td>Start a stopped container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker restart 
</code></pre></td><td>Restart a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker rm 
</code></pre></td><td>Remove a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker exec -it  
</code></pre></td><td>Execute a command in a running container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker logs 
</code></pre></td><td>View the logs of a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker stats
</code></pre></td><td>Display a live stream of container resource usage</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker attach 
</code></pre></td><td>Attach to a running container's STDIN, STDOUT, and STDERR</td></tr></tbody></table>

## Docker Containers

### Managing Containers

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker top 
</code></pre></td><td>Display the running processes of a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker inspect 
</code></pre></td><td>View detailed information about a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker rename  
</code></pre></td><td>Rename a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker update 
</code></pre></td><td>Update the configuration of a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker diff 
</code></pre></td><td>Inspect changes to files or directories in a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker wait 
</code></pre></td><td>Block until a container stops, then print its exit code</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker export 
</code></pre></td><td>Export a container's file system as a tar archive</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker cp : 
</code></pre></td><td>Copy files/folders between a container and host</td></tr></tbody></table>

### Container Networking

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker network ls
</code></pre></td><td>List Docker networks</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker network create 
</code></pre></td><td>Create a Docker network</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker network inspect 
</code></pre></td><td>View detailed information about a network</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker network connect  
</code></pre></td><td>Connect a container to a network</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker network disconnect  
</code></pre></td><td>Disconnect a container from a network</td></tr></tbody></table>

### Container Health

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker container stats
</code></pre></td><td>Display a live stream of container resource usage</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker container stats 
</code></pre></td><td>Display resource usage of a specific container</td></tr></tbody></table>

## Docker Images

### Managing Images

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker save 
</code></pre></td><td>Save a Docker image to a tar archive file</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker load -i &#x3C;image.tar>
</code></pre></td><td>Load a Docker image from a tar archive file</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image prune
</code></pre></td><td>Remove all dangling images</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image ls
</code></pre></td><td>List Docker images</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image history 
</code></pre></td><td>Show the history of an image</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image build -t  
</code></pre></td><td>Build a Docker image from a Dockerfile</td></tr></tbody></table>

### Building Images

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker commit 
</code></pre></td><td>Create a new image from a container</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker build -t  
</code></pre></td><td>Build a Docker image from a Dockerfile</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker build -t  - &#x3C; Dockerfile
</code></pre></td><td>Build an image from a Dockerfile from stdin</td></tr></tbody></table>

### Image Tagging and Publishing

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker tag  
</code></pre></td><td>Create a tag for an image</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker push 
</code></pre></td><td>Push an image to a registry</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker image inspect 
</code></pre></td><td>View detailed information about an image</td></tr></tbody></table>

## Docker Compose

### Managing Compose

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker-compose up
</code></pre></td><td>Start services defined in a <code>docker-compose.yml</code></td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker-compose up -d
</code></pre></td><td>Start services in detached mode</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker-compose down
</code></pre></td><td>Stop and remove services defined in <code>docker-compose.yml</code></td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker-compose logs
</code></pre></td><td>View container logs for services in a compose file</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker-compose ps
</code></pre></td><td>List containers of services in a compose file</td></tr></tbody></table>

## Docker Swarm

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">docker swarm init
</code></pre></td><td>Initialize a Docker Swarm mode</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker swarm join-token
</code></pre></td><td>Display the join token for adding nodes to a swarm</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker node ls
</code></pre></td><td>List nodes in a swarm</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker service ls
</code></pre></td><td>List services in a swarm</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker service create
</code></pre></td><td>Create a new service in a swarm</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">docker stack deploy
</code></pre></td><td>Deploy a new stack in a swarm</td></tr></tbody></table>

<figure><img src="/files/kwUoza9RlvZL1xSoruk7" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fastiraz.gitbook.io/doc/documentations/cheat-sheet/docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
