Docker Cheat Sheet
Docker is an excellent platform for designing, deploying, and executing programs that rely on containers. Docker allows you to construct a container that contains your program, well any packages or libraries that it relies on, as well as any configuration information. When you managed to make a webpage, you used to have to buy a server, install Linux, build up a LAMP architecture, and then run the program. If your program became famous, you used effective load balancing by adding an extra server to guarantee that it didn't crash due to excessive traffic.
The best thing about open source is whether you get to choose the tech you want to employ to finish a job. Docker engine is suitable for single engineers that want a lightweight, pure environment to run but do not require extensive management.
Docker Community Edition (docker-ce) is a wonderful method to begin with containers if Docker is installed on your system and everyone around you is comfortable with the Docker ecosystem. Because the fight to ensure open standards prevails is continuous, sticking with projects that love and appreciate open source should be a long-term plan for your container solution. Private extras may appear interesting at first, but once you lock your tools to a solution that does not allow for the transfer, you lack your freedom of choice. Containers may be freed if they're used correctly.
In this cheat sheet, we will highlight all the important docker commands that caters to freshers and experienced professionals, so let's move forward.
Docker Tutorial: Freshers and Experienced
1. Installation of Docker
Command | Meaning | Syntax |
---|---|---|
For Windows | This command helps you to install Docker on windows. | https://download.docker.com/win/stable/InstallDocker.msi |
For Linux | This command helps you to install Docker on Linux. | curl -sSL https://get.docker.com/ | sh |
For mac | This command helps you to install Docker on mac os. | https://download.docker.com/mac/stable/Docker.dmg |
2. Docker Registry and Repository
Command | Meaning | Syntax |
---|---|---|
Login to a Registry | This command helps you log in to your Registry. |
|
Logout from a registry: | This command helps you log out from your Registry. |
|
Searching an image | By using this docker command you can search any image from your docker. |
|
Pulling an Image | This command can be used to download a specific image or set of images. |
|
Pushing an image | This command can be used to push a specific image or set of images. |
|
3. Running Containers
Command | Meaning | Syntax |
---|---|---|
Command to create a container | This command is used to create a container without running |
|
Command to run a container | This command is used to run a container |
|
Command to rename a container | Use this command to rename a container |
|
Command for removing a container | This command is used to remove container in the topic |
|
Update a container | This command is used to update container in the topic |
|
4. Commands for Starting or Stopping the Container
Command | Meaning | Syntax |
---|---|---|
Command for starting a container | This command is used for starting a container |
|
Command for stopping a container | This command is used for stopping a container |
|
Command for restarting the container | This command is used for restarting a container |
|
Command for pausing the container | This command is used for pausing a container |
|
Command for unpausing the container | This command is used for unpausing a container in the docker |
|
Command for Blocking a container | This command is used for blocking a container in the docker |
|
Sending a SIGKILL | This command is used for Sending a SIGKILL in the docker |
|
Command for sending another signal | This command is used for for sending another signal |
|
Command for Connecting to an Existing Container | We can use this command for Command for Connecting to an Existing Container |
|
5. Commands for Obtaining Container Information
Command | Meaning | Syntax |
---|---|---|
Fetching information From Running Containers | We can fetch information from running container by using this command |
Or
|
Command for fetching about every container | This command for fetching about every container |
Or
|
Command for container log | We can use this command to see the container log |
|
Command for ‘tail -f’ Containers’ Logs | With this command Container isn't running in the foreground, and if there isn't anything running in the foreground, Docker closes automatically. |
|
Command for Inspecting Containers
|
This is the command use for inspecting containers |
|
Command for Containers Events | To obtain real-time events from the server, use docker events. |
|
Command for Public Ports | Use this command for finding a public port |
|
Command for Running Processes | We can use this commands for displaying the running processes in the container |
|
Command for Container Resource Usage | It displays a live stream of resources usage statics for containers |
|
Commands for Inspecting changes to files or directories on a container’s filesystem | This command is used for inspecting changes to files or directories on a container’s filesystem |
|
6. Commands for Managing Images
Command | Meaning | Syntax |
---|---|---|
Commands for listing images | This command is used to listing images |
|
Command for Building images From the current directory's Dockerfile | This command is used for building from the current directory’s dockerfile |
|
Command for Building images From a GIT remote repository | This command is used Building images command Using a remote GIT repository |
|
Commands for tagging and building | This command for tagging and building. |
|
Specifying the Build Context while creating a Dockerfile | This is use to Build an image from a Dockerfile |
|
Creating a Dockerfile from a URL | It wil help to create a dockerfile with a specific URL. |
|
Command for removing image | This command is used to removing a7n image |
|
Using a File or the Normal Input Stream to Load a Tarred Repository | Use STDIN or a tar archive to load an image. |
|
Image Saving to a Tar Archiveard Input Stream | It is used Save one or more images to a tar archive |
|
Showing the History of an Image | This command will let know the history of the image inside the docker |
|
Making an Image Out of a Container | This command will help you to take an image out of the container |
|
Command for image tagging | We can use this command for image tagging |
|
Command for pushing an image | We can push any image through this command |
|
7. Commands for Networking
Command | Meaning | Syntax |
---|---|---|
Command for overlay network | This is used to establish a distributed network between many Docker daemon hosts. |
|
Command for Bridge network | To establish container test1 to bridge demo-bridge, type docker network connect demo-bridge test1. |
|
Command for removing a network | This command s used to remove an overlay network |
|
Command for network listing | This command is used to listing the overlay networks |
|
Command for Getting Information About a Network | We can get information about an overlay network with the help of this command |
|
Command for Connecting a Running Container to a Network | By using this command we can connect a container to network |
|
Command for Connecting a Container to a Network When it Starts | When the container starts we can use this command to connect a container to network |
|
Command for Disconnecting a Container from a Network | We can use this Command for disconnecting a container from network |
|
Command for Exposing Ports | We can expose the empty ports using this command |
|
8. Commands for Cleaning Docker
Command | Meaning | Syntax |
---|---|---|
Command for Removing a Running Container | We can remove a running container by using this command |
|
Command for Removing a Container and its Volume | We can use this command for removing the container and the things inside it |
|
Command for Removing all Exited Containers | We can use this command for removing all the exited containers |
|
Command for Removing All Stopped Containers | We can remove all the stopped containers by using this command |
|
Command for Removing a Docker Image | This command is used fr removing a docker image |
|
Command for Dangling Images | We can dangle the images with this command |
|
Command for Removing all Images | We can remove all the image in the docker by using this commands |
|
Commands for Delete all Untagged Images | We can delete all the untagged images with the use of this command |
|
Command for Stopping & Removing all Containers | For stopping and removing all the container we can use this command |
|
Command for Removing Dangling Volumes | We can remove all the dangling volumes by using this command |
|
Command for removing all unneeded (containers, images, networks and volumes) | This command is use to remove the unnecessary thing |
|
Command for Clean all | We cam use this command for cleaning everything in the docker |
|
Conclusion
You should have a solid knowledge of what Docker is and how it operates by this point. Docker's finest feature is cooperation. Docker images may be uploaded to a repo and then downloaded to any other server to execute containers. Furthermore, the Docker hub has hundreds of images developed by users, which you may download down to your servers depending on your specific application. It is also often used throughout container orchestration technologies such as Kubernetes.
Docker is one of the greatest production technologies available today, and its demand is expanding rapidly. It is considered ideal for larger businesses, and because it is open-source, it is a versatile platform that can be used to construct a wide range of applications.
References and Resources
- Official Documentation: https://docs.docker.com/engine/reference/commandline/docker/
- Docker Interview Questions: https://www.interviewbit.com/docker-interview-questions/
- Docker Commands with Examples: https://www.interviewbit.com/blog/docker-commands/
Docker MCQ
What does the CMD instruction do if the ENTRYPOINT command is also used?
What is a decent docker exec analogy?
When you load Docker runtime on a Docker host, which one of the following network interfaces is created?
Which command provides access to the live output of processes operating within a container?
Which Docker CLI commands should be used in what order to produce a Docker image?
Which Docker component interacts with the kernel primitives needed to generate containers?
Which Dockerfile instruction specifies the base image to be used?
Which of the below best describes the connection between a Docker image and a Docker container?