You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, you need to login to the docker hub using the following command.
875
+
```bash
876
+
docker login
877
+
```
878
+
You will see the following output.
879
+
```bash
880
+
Logging in with your password grants your terminal complete access to your account.
881
+
```
882
+
- Step 7: Now stop the app using the `ctrl+c` command then delete the `node_modules` folder and create a new file and name it `Dockerfile` and paste the following code in it.
883
+
```dockerfile
884
+
FROM node:14.17.0-alpine3.13
885
+
WORKDIR /app
886
+
COPY . /app
887
+
RUN npm install
888
+
EXPOSE 5000
889
+
CMD node index.js
890
+
```
891
+
892
+
- Step 8: Now run the following command to build the docker image.
- Step 14: Now let's delete the docker image from the local system using the following command.
958
+
959
+
> You can do this using the docker desktop app also.
960
+
961
+
#### ⚡ Check the container id
962
+
First, you need to check the image id using the following command.
963
+
```bash
964
+
docker ps
965
+
```
966
+
#### ⚡ Stop the container
967
+
Now run the following command to stop the container.
968
+
```bash
969
+
docker stop <container_id>
970
+
```
971
+
> In my case, the container id is `b3b0b5b5b9b0` so I will run the following command `docker stop b3b0b5b5b9b0`.
972
+
973
+
#### ⚡ Kill the container
974
+
Now run the following command to kill the container.
975
+
```bash
976
+
docker kill<container_id>
977
+
```
978
+
> This will send a signal to the container to gracefully stop. If you want to forcefully stop the container immediately, you can use the docker kill command instead:`docker stop <container_id>`
979
+
980
+
#### ⚡ Remove the container
981
+
You can remove the container using the `docker rm` command followed by the container ID. For example, to remove the container with ID `b9061e6d08b6`, you can use the following command:
982
+
```bash
983
+
docker rm b9061e6d08b6
984
+
```
985
+
#### ⚡ Remove the image
986
+
After removing the container, you can then delete the image using the `docker rmi` command:
987
+
```bash
988
+
docker rmi <image_id>
989
+
```
990
+
> In my case, the image id is `a0dacd3ecd79e1252ca8e8a655902af1b6ae98ee609cdee91056c67a6ca00a5c` so I will run the following command `docker rmi a0dacd3ecd79e1252ca8e8a655902af1b6ae98ee609cdee91056c67a6ca00a5c`.
991
+
> This will delete the image from your system.
992
+
993
+
- Step 15: Now run the following command to pull the docker image from the docker hub.
- Step 16: Now run the following command to run the docker image.
1000
+
```bash
1001
+
docker run -d -p 5001:5000 subham4041/second-node-app:0.0.1.RELEASE
1002
+
```
1003
+
Now visit the `localhost:5001` and you will see the following output.
1004
+
```json
1005
+
{
1006
+
"message": "Hello World!"
1007
+
}
1008
+
```
1009
+
1010
+
## 🥰 What did we understand from these two projects?
1011
+
1012
+
If someone pulls the docker image from the docker hub, then they don't need to install the nodejs and npm in their system. They just need to install the docker in their system and then they can run the docker image and they can easily access the application without installing the nodejs and npm in their system. This is the **magic of docker.**
1013
+
1014
+
## ✨ Docker CLI Cheat Sheet
1015
+
1016
+
### 1. Installation
1017
+
1018
+
| Command | Meaning | Syntax |
1019
+
| --- | --- | --- |
1020
+
| For Windows | This command helps you to install Docker on Windows. |`https://download.docker.com/win/stable/InstallDocker.msi`|
1021
+
| For Linux | This command helps you to install Docker on Linux. | `curl -sSL https://get.docker.com/| sh` |
1022
+
| For Mac | This command helps you to install Docker on Mac OS. |`https://download.docker.com/mac/stable/Docker.dmg`|
1023
+
1024
+
### 2. Docker Registry and Repository
1025
+
1026
+
| Command | Meaning | Syntax |
1027
+
| --- | --- | --- |
1028
+
| Login to a Registry | This command helps you log in to your Registry. |`docker login [options] [server]`|
1029
+
| Logout from a registry | This command helps you log out from your Registry. |`docker logout [server]`|
1030
+
| Searching an image | By using this docker command you can search any image from your docker. |`docker search [options] term`|
1031
+
| Pulling an image | This command can be used to download a specific image or set of images. |`docker pull [options] name[:tag]`|
1032
+
| Pushing an image | This command can be used to push a specific image or set of images. |`docker push [options] name[:tag]`|
1033
+
1034
+
### 3. Running Containers
1035
+
1036
+
| Command | Meaning | Syntax |
1037
+
| --- | --- | --- |
1038
+
| Running a container from an image | This command creates and starts a container from an image. You can specify various options such as ports, volumes, environment variables, etc. |`docker run [options] image[:tag] [command] [args]`|
1039
+
| Listing running containers | This command shows all the containers that are currently running. You can use filters and format options to customize the output. |`docker ps [options]`|
1040
+
| Listing all containers (running and stopped) | This command shows all the containers that exist on your system, regardless of their status. You can use filters and format options to customize the output. |`docker ps -a [options]`|
1041
+
| Stopping a container | This command stops a running container by sending a SIGTERM signal and then a SIGKILL signal if the container does not stop within a grace period. You can specify multiple containers to stop at once. |`docker stop [options] container [container...]`|
1042
+
| Starting a stopped container | This command starts a stopped container by restoring its state. You can specify multiple containers to start at once. |`docker start [options] container [container...]`|
1043
+
| Restarting a container | This command restarts a running or stopped container by stopping and then starting it again. You can specify multiple containers to restart at once. |`docker restart [options] container [container...]`|
1044
+
| Removing a container | This command removes one or more containers from your system. You can use filters and force options to remove containers that are running or have volumes attached to them. |`docker rm [options] container [container...]`|
1045
+
1046
+
1047
+
### 4. Managing Images
1048
+
1049
+
| Command | Meaning | Syntax |
1050
+
| --- | --- | --- |
1051
+
| Building an image from a Dockerfile | This command builds an image from a Dockerfile and optionally tags it with a name and tag. You can specify various options such as build arguments, cache settings, etc. |`docker build [options] path`|
1052
+
| Removing an image from your system | This command removes one or more images from your system. You can use filters and force options to remove images that are in use or have dependent images. |`docker rmi [options] image [image...]`|
1053
+
| Tagging an image with a name and tag | This command assigns a name and tag to an image. You can use this to create aliases for images or to prepare them for pushing to a registry. |`docker tag [options] image[:tag] name[:tag]`|
1054
+
| Saving an image to a tar archive | This command saves one or more images to a tar archive file. You can use this to backup or transfer images between systems. |`docker save [options] image [image...] -o file`|
1055
+
| Loading an image from a tar archive | This command loads one or more images from a tar archive file. You can use this to restore or import images from a backup or another system. |`docker load [options] -i file`|
1056
+
1057
+
### 5. Managing Volumes
1058
+
1059
+
| Command | Meaning | Syntax |
1060
+
| --- | --- | --- |
1061
+
| Creating a volume | This command creates a volume on your system. You can specify various options such as name, driver, labels, etc. |`docker volume create [options] [name]`|
1062
+
| Listing volumes on your system | This command shows all the volumes that are stored on your system. You can use filters and format options to customize the output. |`docker volume ls [options]`|
1063
+
| Inspecting a volume | This command shows detailed information about a specific volume. You can use this to check the status, driver, mount point, etc. of a volume. |`docker volume inspect [options] volume [volume...]`|
1064
+
| Removing a volume from your system | This command removes one or more volumes from your system. You can use filters and force options to remove volumes that are in use or have dependent containers. |`docker volume rm [options] volume [volume...]`|
1065
+
| Pruning unused volumes from your system | This command removes all the volumes that are not referenced by any containers from your system. You can use filters to exclude some volumes from pruning. |`docker volume prune [options]`|
1066
+
1067
+
### 6. Managing Networks
1068
+
1069
+
| Command | Meaning | Syntax |
1070
+
| --- | --- | --- |
1071
+
| Creating a network | This command creates a network on your system. You can specify various options such as name, driver, subnet, etc. |`docker network create [options] [name]`|
1072
+
| Listing networks on your system | This command shows all the networks that are available on your system. You can use filters and format options to customize the output. |`docker network ls [options]`|
1073
+
| Inspecting a network | This command shows detailed information about a specific network. You can use this to check the status, driver, IP range, connected containers, etc. of a network. |`docker network inspect [options] network [network...]`|
1074
+
| Removing a network from your system | This command removes one or more networks from your system. You can use filters and force options to remove networks that are in use or have dependent containers. |`docker network rm [options] network [network...]`|
1075
+
| Pruning unused networks from your system | This command removes all the networks that are not used by any containers from your system. You can use filters to exclude some networks from pruning. |`docker network prune [options]`|
1076
+
1077
+
### 7. Miscellaneous Commands (continued)
1078
+
1079
+
| Command | Meaning | Syntax |
1080
+
| --- | --- | --- |
1081
+
| Getting help on docker commands and options | This command shows the usage and options for any docker command or subcommand. You can use this to learn more about how to use docker. |`docker [command] --help`|
1082
+
| Getting the version of docker | This command shows the version and build information of docker on your system. You can use this to check if you have the latest version or if you need to update. |`docker version [options]`|
1083
+
| Getting system-wide information on docker | This command shows system-wide information about docker on your system. You can use this to check the status, resources, configuration, etc. of docker. |`docker info [options]`|
1084
+
| Executing a command in a running container | This command executes a command in a running container and returns the output. You can use this to run commands that are not available in the container's shell or to interact with the container's processes. |`docker exec [options] container command [args]`|
1085
+
| Attaching to a running container | This command attaches your terminal to a running container's standard input, output, and error streams. You can use this to interact with the container's shell or processes. |`docker attach [options] container`|
1086
+
| Copying files or folders between a container and your system | This command copies files or folders between a container and your system. You can use this to transfer data to or from a container. |`docker cp [options] source destination`|
1087
+
| Viewing logs from a container | This command shows the logs from a container's standard output and error streams. You can use this to monitor or troubleshoot a container's activity. |`docker logs [options] container`|
1088
+
| Committing changes to an image | This command creates a new image from a container's changes. You can use this to save your modifications or to create new images based on existing ones. |`docker commit [options] container [repository[:tag]]`|
1089
+
| Building an image from stdin or a URL | This command builds an image from a Dockerfile that is provided through stdin or a URL. You can use this to build images from remote sources or scripts. |`docker build [options] - < Dockerfile` or `docker build [options] url`|
1090
+
| Showing the history of an image | This command shows the history of an image, including the layers and commands that were used to create it. You can use this to inspect how an image was built or to optimize it. |`docker history [options] image`|
0 commit comments