Docker Commands

Docker commands to run docker

  • docker build
    • docker build -t <tagname>:<tagversion> /<path>/<to>/Dockerfile
      • Example : docker build -t helloworld:0.1 .
    • Passing Docker file as an argument
      • Example : docker build -f test1-docker-running/running.Dockerfile -t helloworld:0.2 .
    • Pass Dockerfile name as a standard input
      • Example : docker build -t helloworld:0.1 – < running.Dockerfile
  • docker images
    • prints the list of images available in docker
  • docker run (docker container run (is the new management command alternative))
    • Run the image to create a container
      • Example : docker run helloworld:0.1
    • You can run the application in background using -d attribute
      • Example : docker run -d helloworld:0.1
    • Name you container using –name
      • Example : docker run –name my-app -d helloworld:0.1
    • Binding ports
      • Example : docker run –name app -d -p 9090:8080 helloworld:01
      • 9090 Host port
      • 8080 Docker port which is exposed
  • docker ps (docker container ls (is the new management command alternative))
    • list of running containers
    • ps -a
      • displays running and stopped containers
  • docker logs
    • docker log command prints the logs of the container
    • First your need to find the running container id by using command docker ps
    • Then run the command docker logs 1E733HJERT17772KRM
  • docker stop (docker container stop (is the new management command alternative))
    • Stops the container
      • Example docekr stop my-app
  • docker rm
    • Remove the image
      • Example docker rm my-app
    • Remove the image + stop the containers
      • Exammple : docker rm -f my-app
  • docker network
    • Creates a connectivity between two containers
    • list the connectiivty with ls
      • Example : docker network ls
    • Default network connectivity is bridge
    • Create a bridge network
      • Example : docker nework create app-network
  • version
    • To check docker version
    • Example : docker version
  • info
    • To find more info on docker
    • Example : docker info
  • pull
    • To pull a image from docker hum
    • Syntax : docker pull <repository>:<tag-version>
    • Example : docker pull openjdk:8u302-jdk-slim

Docker Commands & Management Commands

  • Old docker commands use to be like docker<space><command>
  • Example : docker run
  • New docker commands however are like docker<space><command><space><subcommand>
  • Example : Docker container run
  • Both docker run and docker container run does the same thing it is just the old and new way
  • New way cameup when they had a lot of commands in hand then they had to split the commands into 2 sections. This is called Management commands
  • Docker however is backward compactable and the old commands will not be deprecated

Manual (Man) of Docker

  • You can find the docker commands just by typing docker in console
  • Example : docker
    • All the commands are listed
  • Example : docker container –help
    • All the subcommands for the command container is listed

Reference :

Leave a Comment