Skip to content

Commit

Permalink
Added Docker basic commands section-wise
Browse files Browse the repository at this point in the history
  • Loading branch information
Defcon27 committed Feb 20, 2023
1 parent eba4e5f commit 8248f48
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
133 changes: 133 additions & 0 deletions Container-orchestration/Docker/docker-basic-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<h1 align="center">Docker Basic Commands</h1>

## Build Images

- Create image using current directory’s Dockerfile <br>
``` docker build -t image-name . ```

- List images<br>
``` docker images ```

<br>

## Running Container

- Create new container from specified image<br>
``` docker run image-name ```

- Assign a name to the container<br>
``` docker run --name nick-name image-name ```

- Run image with an entry point | override existing entrypoint<br>
```docker run image-name cmd```<br>
```docker run image-name --entrypoint cmd```

- Run image in interactive mode<br>
``` docker run -it image-name ```

- Run image in detached mode<br>
``` docker run -d image-name ```

- Run image mapping container's port to the host<br>
``` docker run -p host-port:container-port image-name ```

<br>

## Managing Containers

- List running containers<br>
``` docker ps ```

- List all containers<br>
```docker ps -a```

- Stop one or more running containers<br>
```docker stop containerId```

- Start one or more stopped containers<br>
```docker start containerId```

- Fetch the logs of a container<br>
```docker logs containerId```

- Fetch and follow log output of a container<br>
```docker logs -f containerId```

- Run a command in a running container in interactive mode<br>
```docker exec -it containerId cmd```

- Copy files/folders from container to local filesystem<br>
``` docker cp containerId:/workdir/file.ext .```

- Copy files/folders from local filesystem to container<br>
``` docker cp file.ext containerId:/workdir/```

- Remove container<br>
```docker rm containerId```

- Remove running container<br>
```docker rm -f containerId```

- Remove all running and stopped containers<br>
```docker rm -f $(docker ps -a -q)```

<br>


## Persistant data using Volumes

- Creates a new volume that containers store data<br>
```docker volume create volume-name```

- Display detailed information on one or more volumes<br>
```docker volume inspect volume-name```

- List volumes<br>
```docker volume ls```

- Create a volume and then configure the container to use it<br>
``` docker run -v volume-name:/dir/dir container-name```

- Create mapping between dir in host and container<br>
``` docker run -v $(pwd):/workdir container-name```




<br>

## Managing Images

#### Tagging Images

- Create tag to the image while building<br>
``` docker build -t image-name:tag . ```

- Create tag to the image after building<br>
``` docker image tag src-image:latest dst-image:tag ```

#### Saving & Loading Images

- Save one or more images to a tar archive<br>
``` docker image save -o image-name.tar image-name:tag ```

- Load an image from a tar archive<br>
``` docker image load -i image-name.tar ```

#### Remove Images

- Remove one or more images<br>
``` docker image rm image-name ```<br>
``` docker rmi image-name ```

- Remove all images<br>
``` docker system prune -a ```

- Remove all stopped containers<br>
``` docker container prune ```

- Remove all dangling images<br>
``` docker image prune ```

- Remove all unused containers, networks, dangling and unreferenced images<br>
``` docker system prune ```
3 changes: 3 additions & 0 deletions Container-orchestration/Docker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


*****************
[`Docker Basic Commands`](docker-basic-commands.md)

[`Docker Complete Commands`](docker-commands.md)
*****************
## 1. Basic concepts of docker - Containers and Images

- Detailed Docker concepts and notes from here - [Docker Concepts](https://github.com/Tikam02/DevOps-Guide/blob/master/Container-orchestration/Docker/docker-concepts.md)
Expand Down

0 comments on commit 8248f48

Please sign in to comment.