We earn commission when you buy through affiliate links.
This does not influence our reviews or recommendations.Learn more.
There are several docker commands you must know when working with Docker.
This article is all about that.
If you dont know what Docker is, then you may take thisUdemy beginner course.
Downloading image
Lets say you should probably pull the docker image fromdockerhub(docker repository).
The following example of pulling the Apache HTTP server image.
Run
launch the docker image mentioned in the command.
This command will create a docker container in which the Apache HTTP server will run.
Whats running?
pslists all the docker containers are running with container details.
As you might see, the Apache server is running in this docker container.
ps -a
List all the docker containers running/exited/stopped with container details.
exec
reach the docker container and run commands inside the container.
I am accessing the apache server container in this example.
Typeexitand press enter to come out of the container.
Removing container
Remove the docker container with container id mentioned in the command.
spin up the below command to look to see if the container got removed or not.
fire off the command below and check the STATUS parameter to verify if the container started recently.
Stopping Docker
Stop a container with container id mentioned in the command.
trigger the below command to peek if the container is still running or it has stopped.
Starting Docker
This command in docker starts the docker container with container id mentioned in the command.
spin up the command below to look to see if the container started or not.
Kill
Stop the docker container immediately.
Docker stop command stops the container gracefully, thats the difference between a kill and stop commands.
execute the below command to see if the container got killed or not.
Commit
Save a new docker image with container id mentioned in the command on the local system.
In the example below, geekflare is the username, and httpd_image is the image name.
Login
Login into docker hub.
You will be asked your docker hub credentials to access.
Push
Upload a docker image with the image name mentioned in the command on the dockerhub.
There are several other docker web connection commands.
Copying file
Copy a file from a docker container to the local system.
Checking history
Shows the history of a docker image with the image name mentioned in the command.
Checking logs
Show the logs of the docker container with contained id mentioned in the command.
Searching image
Search for a docker image on dockerhub with the name mentioned in the command.
Updating configuration
Update container configurations.
This shows all the update options.
trigger the below command to update the CPU configuration of docker container with container id mentioned in the command.
Creating volume
Create a volume which docker container will use to store data.
initiate the below command if the volume got created or not.
Installing plugin
Install a docker plugin vieux/sshfs with debug environment set to 1.
Logout
Logging out from dockerhub.
Conclusion
I hope you have got a fair understanding of docker commands by now.
Try out those commands in your dev or lab environment to practice and learn.
If you are interested in learning Docker and Kubernetes, then check out thisonline course.