Of late I have been exploring on Docker containers. In this post, I have captured most of the commonly used docker commands that one should be aware of while exploring Docker. If you haven’t installed docker yet, follow along the instructions from the official Docker site and install the appropriate version for Mac/Windows.

  1. To verify the version number of the installations.
    • docker -v , docker-compose -v, docker-machine -v
  2. To get to know the list of available docker commands
    • docker help
  3. To search for available docker images
    • docker search <searchtext>
  4. To pull a docker image from docker registry
    • docker pull <imagename>
  5. To list the available images in the local machine
    • docker images
  6. To run a docker image in a new container
    • docker run
    • docker run -d <imagename>  – Run the image in detached mode
    • docker run -it <imagename>– Run the image in interactive mode, this allows to interact with the image using commands
    • docker run --help – To get to know all the switches available for run command
  7. To list the running containers
    • docker ps
  8. To list all the containers
    • docker ps -a
  9. To start a container
    • docker start <containername>
  10. To stop a container
    • docker stop <containername>
  11. To remove a container
    • docker rm <containerId>
  12. To remove an image
    • docker rmi <imagename>
  13. To build an image from docker file
    • docker build -t <tagname> <contextfolder> – tag name can be any meaningful name; context folder could be the root folder that contains the Dockerfile
  14. To push an image to remote registry
    • docker push <imagename>
  15. To login to the remote registry before pushing the image
    • docker login -u <username> -p <password>

Though this is not a comprehensive list of commands, I have aimed at putting together the most frequently used commands to get started with. More on other docker commands in a future blog post.