0% found this document useful (0 votes)
54 views

Docker Complete Guide.

Docker allows building containers that contain programs, libraries and configuration. Commands are provided to install Docker, pull and push images to registries, run, stop and manage containers, and inspect images and containers. Detailed explanations and syntax are given for over 30 Docker commands.

Uploaded by

Rahul Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Docker Complete Guide.

Docker allows building containers that contain programs, libraries and configuration. Commands are provided to install Docker, pull and push images to registries, run, stop and manage containers, and inspect images and containers. Detailed explanations and syntax are given for over 30 Docker commands.

Uploaded by

Rahul Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Introduction

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

1
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 This command helps you to
Windows 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 This command helps you log in to your docker login
Registry Registry. docker login localhost:8080

Logout from a This command helps you log out from your docker logout
registry: Registry. docker logout localhost:8080

Searching an search nginx


By using this docker command you can search docker search --filter stars=3 --no-trun
image
any image from your docker. c nginx

Pulling an Image docker image pull nginx


This command can be used to download a docker image pull eon01/nginx localho
specific image or set of images. st:5000/myadmin/nginx

Pushing an docker image push eon01/nginx


This command can be used to push a specific docker image push eon01/nginx localh
image
image or set of images. ost:5000/myadmin/nginx

2
3. Running Containers

Command Meaning Syntax


Command to create a This command is used to create a docker container create -t -i eon01/infi
container container without running nite --name XYZ

Command to run a This command is used to run a docker container run -it --name XYZ -
container container d eon01/infinite

Command to rename a Use this command to rename a


container container docker container rename XYZ infinity

Command for removing This command is used to remove


a container container in the topic docker container rm infinite

Update a container This command is used to update docker container update --cpu-shares
container in the topic 512 -m 300M infinite

4. Commands for Starting or Stopping the Container

Command Meaning Syntax


Command for starting a This command is used for starting a docker container start
container container nginx

Command for stopping a This command is used for stopping a docker container stop
container container nginx

Command for restarting the This command is used for restarting a docker container rest
container container art nginx

Command for pausing the docker container pau


container This command is used for pausing a container se nginx
Command for unpausing the This command is used for unpausing a docker container unp
container container in the docker ause nginx

Command for Blocking a This command is used for blocking a docker container wait
container container in the docker nginx

3
Command Meaning Syntax
Sending a SIGKILL This command is used for Sending a SIGKILL docker container kill
in the docker nginx

Command for sending another This command is used for for sending another docker container kill -
signal signal s HUP nginx

Command for Connecting to We can use this command for Command for docker container atta
an Existing Container Connecting to an Existing Container ch nginx

5. Commands for Obtaining Container Information

Command Meaning Syntax


Fetching information From docker ps

Running Containers
Or
We can fetch information from running container
by using this command docker container ls

Command for fetching about docker container ls


-a
every container

Or

This command for fetching about every container docker ps -a


Command for container log We can use this command to see the container
log docker logs infinite

Command for ‘tail -f’ With this command Container isn't running in the
Containers’ Logs foreground, and if there isn't anything running in docker container lo
the foreground, Docker closes automatically. gs infinite -f

Command for Inspecting docker container in


spect infinite
Containers

docker container in
This is the command use for inspecting spect --format '' $(
containers docker ps -q)

Command for Containers To obtain real-time events from the server, use docker system eve
Events docker events. nts infinite

4
Command Meaning Syntax
Command for Public Ports docker container p
Use this command for finding a public port ort infinite

Command for Running We can use this commands for displaying the docker container to
Processes running processes in the container p infinite

Command for Container It displays a live stream of resources usage docker container st
Resource Usage statics for containers ats infinite

Commands for Inspecting


changes to files or directories This command is used for inspecting changes to docker container di
on a container’s filesystem files or directories on a container’s filesystem ff infinite

6. Commands for Managing Images

Command Meaning Syntax


Commands for listing images This command is used to listing
images docker image ls

Command for Building images This command is used for building


From the current directory's from the current directory’s dockerfile
Dockerfile docker build

Command for Building images This command is used Building


From a GIT remote repository images command Using a remote GIT docker build github.com/cre
repository ack/docker-firefox

Commands for tagging and This command for tagging and


building building. docker build -t eon/infinite

Specifying the Build Context while This is use to Build an image from a docker build -f myDockerfil
creating a Dockerfile Dockerfile e

Creating a Dockerfile from a URL It wil help to create a dockerfile with curl example.com/remote/D
a specific URL. ockerfile | docker build -f -

Command for removing image This command is used to removing


a7n image docker image rm nginx

Using a File or the Normal Input


docker image load < ubunt
Stream to Load a Tarred Use STDIN or a tar archive to load u.tar.gz
Repository an image.

5
Command Meaning Syntax
docker build -f myOtherDo
ckerfile

Image Saving to a Tar Archiveard It is used Save one or more images docker image save busybo
Input Stream to a tar archive x > ubuntu.tar

Showing the History of an Image This command will let know the
history of the image inside the docker image history
Making an Image Out of a This command will help you to take docker container commit n
Container an image out of the container ginx

Command for image tagging We can use this command for image docker image tag nginx eo
tagging n01/nginx

Command for pushing an image We can push any image through this docker image push eon01/
command nginx

7. Commands for Networking

Command Meaning Syntax


Command for overlay network This is used to establish a distributed
network between many Docker daemon docker network create -d
hosts. overlay MyOverlayNetwork

Command for Bridge network To establish container test1 to bridge


demo-bridge, type docker network connect docker network create -d
demo-bridge test1. bridge MyBridgeNetwork

Command for removing a This command s used to remove an docker network rm MyOve
network overlay network rlayNetwork

Command for network listing This command is used to listing the


overlay networks docker network ls

Command for Getting We can get information about an overlay docker network inspect My
Information About a Network network with the help of this command OverlayNetwork

Command for Connecting a


Running Container to a By using this command we can connect docker network connect M
Network a container to network yOverlayNetwork nginx

6
Command Meaning Syntax
Command for Connecting a When the container starts we can use
docker container run -it -d
Container to a Network When this command to connect a container to --network=MyOverlayNetwo
it Starts network rk nginx

Command for Disconnecting a We can use this Command for docker network disconnect
Container from a Network disconnecting a container from network MyOverlayNetwork nginx

Command for Exposing Ports We can expose the empty ports using
this command EXPOSE <port_number>

8. Commands for Cleaning Docker

Command Meaning Syntax


Command for Removing a We can remove a running
Running Container container by using this
command docker container rm nginx

Command for Removing a We can use this command for


Container and its Volume removing the container and the
things inside it docker container rm -v nginx

Command for Removing all We can use this command for


Exited Containers removing all the exited docker container rm $(docker contain
containers er ls -a -f status=exited -q)

Command for Removing All We can remove all the stopped


Stopped Containers containers by using this docker container rm `docker containe
command r ls -a -q`

Command for Removing a This command is used fr


Docker Image removing a docker image docker image rm nginx

Command for Dangling Images We can dangle the images with docker image rm $(docker image ls -
this command f dangling=true -q)

Command for Removing all We can remove all the image


Images in the docker by using this docker image rm $(docker image ls -
commands a -q)

7
Command Meaning Syntax
Commands for Delete all We can delete all the untagged
Untagged Images images with the use of this docker image rm -f $(docker image l
command s | grep "^<none>" | awk "{print $3}")

Command for Stopping & For stopping and removing all


docker container stop $(docker contai
Removing all Containers the container we can use this ner ls -a -q) && docker container rm
command $(docker container ls -a -q)

Command for Removing We can remove all the dangling docker volume rm $(docker volume l
Dangling Volumes volumes by using this command s -f dangling=true -q)
Command for removing all
unneeded (containers, images, This command is use to
networks and volumes) remove the unnecessary thing docker system prune -f

Command for Clean all 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.

8
9

You might also like