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
This command helps you to install Docker on windows. | //download.docker.com/win/stable/InstallDocker.msi |
This command helps you to install Docker on Linux. | curl -sSL //get.docker.com/ | sh |
This command helps you to install Docker on mac os. | //download.docker.com/mac/stable/Docker.dmg |
2. Docker Registry and Repository
This command helps you log in to your Registry. | docker login docker login localhost:8080 |
This command helps you log out from your Registry. | docker logout docker logout localhost:8080 |
By using this docker command you can search any image from your docker. | search nginx docker search --filter stars=3 --no-trunc nginx |
This command can be used to download a specific image or set of images. | docker image pull nginx docker image pull eon01/nginx localhost:5000/myadmin/nginx |
This command can be used to push a specific image or set of images. | docker image push eon01/nginx docker image push eon01/nginx localhost:5000/myadmin/nginx |
3. Running Containers
This command is used to create a container without running | docker container create -t -i eon01/infinite --name XYZ |
This command is used to run a container | docker container run -it --name XYZ -d eon01/infinite |
Use this command to rename a container | docker container rename XYZ infinity |
This command is used to remove container in the topic | docker container rm infinite |
This command is used to update container in the topic | docker container update --cpu-shares 512 -m 300M infinite |
4. Commands for Starting or Stopping the Container
This command is used for starting a container | docker container start nginx |
This command is used for stopping a container | docker container stop nginx |
This command is used for restarting a container | docker container restart nginx |
This command is used for pausing a container | docker container pause nginx |
This command is used for unpausing a container in the docker | docker container unpause nginx |
This command is used for blocking a container in the docker | docker container wait nginx |
This command is used for Sending a SIGKILL in the docker | docker container kill nginx |
This command is used for for sending another signal | docker container kill -s HUP nginx |
We can use this command for Command for Connecting to an Existing Container | docker container attach nginx |
5. Commands for Obtaining Container Information
We can fetch information from running container by using this command | docker ps Or docker container ls |
This command for fetching about every container | docker container ls -a Or docker ps -a |
We can use this command to see the container log | docker logs infinite |
With this command Container isn't running in the foreground, and if there isn't anything running in the foreground, Docker closes automatically. | docker container logs infinite -f |
This is the command use for inspecting containers | docker container inspect infinite docker container inspect --format '' $(docker ps -q) |
To obtain real-time events from the server, use docker events. | docker system events infinite |
Use this command for finding a public port | docker container port infinite |
We can use this commands for displaying the running processes in the container | docker container top infinite |
It displays a live stream of resources usage statics for containers | docker container stats infinite |
This command is used for inspecting changes to files or directories on a container’s filesystem | docker container diff infinite |
6. Commands for Managing Images
This command is used to listing images | docker image ls |
This command is used for building from the current directory’s dockerfile | docker build |
This command is used Building images command Using a remote GIT repository | docker build github.com/creack/docker-firefox |
This command for tagging and building. | docker build -t eon/infinite |
This is use to Build an image from a Dockerfile | docker build -f myDockerfile |
It wil help to create a dockerfile with a specific URL. | curl example.com/remote/Dockerfile | docker build -f - |
This command is used to removing a7n image | docker image rm nginx |
Use STDIN or a tar archive to load an image. | docker image load < ubuntu.tar.gz docker build -f myOtherDockerfile |
It is used Save one or more images to a tar archive | docker image save busybox > ubuntu.tar |
This command will let know the history of the image inside the docker | image history |
This command will help you to take an image out of the container | docker container commit nginx |
We can use this command for image tagging | docker image tag nginx eon01/nginx |
We can push any image through this command | docker image push eon01/nginx |
7. Commands for Networking
This is used to establish a distributed network between many Docker daemon hosts. | docker network create -d overlay MyOverlayNetwork |
To establish container test1 to bridge demo-bridge, type docker network connect demo-bridge test1. | docker network create -d bridge MyBridgeNetwork |
This command s used to remove an overlay network | docker network rm MyOverlayNetwork |
This command is used to listing the overlay networks | docker network ls |
We can get information about an overlay network with the help of this command | docker network inspect MyOverlayNetwork |
By using this command we can connect a container to network | docker network connect MyOverlayNetwork nginx |
When the container starts we can use this command to connect a container to network | docker container run -it -d --network=MyOverlayNetwork nginx |
We can use this Command for disconnecting a container from network | docker network disconnect MyOverlayNetwork nginx |
We can expose the empty ports using this command | EXPOSE <port_number> |
8. Commands for Cleaning Docker
We can remove a running container by using this command | docker container rm nginx |
We can use this command for removing the container and the things inside it | docker container rm -v nginx |
We can use this command for removing all the exited containers | docker container rm $(docker container ls -a -f status=exited -q) |
We can remove all the stopped containers by using this command | docker container rm `docker container ls -a -q` |
This command is used fr removing a docker image | docker image rm nginx |
We can dangle the images with this command | docker image rm $(docker image ls -f dangling=true -q) |
We can remove all the image in the docker by using this commands | docker image rm $(docker image ls -a -q) |
We can delete all the untagged images with the use of this command | docker image rm -f $(docker image ls | grep "^<none>" | awk "{print $3}") |
For stopping and removing all the container we can use this command | docker container stop $(docker container ls -a -q) && docker container rm $(docker container ls -a -q) |
We can remove all the dangling volumes by using this command | docker volume rm $(docker volume ls -f dangling=true -q) |
This command is use to remove the unnecessary thing | docker system prune -f |
We cam use this command for cleaning everything in the docker | docker system prune -a |
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: //docs.docker.com/engine/reference/commandline/docker/
- Docker Interview Questions: //www.interviewbit.com/docker-interview-questions/
- Docker Commands with Examples: //www.interviewbit.com/blog/docker-commands/
Docker MCQ
FROM
ENTRYPOINT
BASE
USING
Allows you to execute other processes outside of a container.
Allows you to run more processes within a container.
It's comparable to installing software
This feature enables you to run extra processes in new containers.
Docker1
Docker0
eth0
eth2
To launch a Docker image, a Docker container is utilized.
A Docker container is a functioning image version.
A Docker container is made up of image layers.
A docker container is made up of two or more images that share the same execution environment.
docker container run, and docker image commit.
docker container diff and docker container commit.
docker container ls, and docker image commit.
docker container run and docker container commit.
docker inspect
docker exec
docker attach
docker run
CMD commands are ignored.
CMD commands take precedence over ENTRYPOINT commands.
CMD commands are interpreted as parameters to ENTRYPOINT.
CMD instructions are used to set up the environment for ENTRYPOINT instructions to run in.
The Docker daemon
The REST API
The OCI layer (runc)