Docker Command(CheatSheet)

Docker Command(CheatSheet)

By - SANDEEP KUMAR PATEL

What is Docker?

Docker is an open source project that makes it easy to create containers and container-based apps. Originally built for Linux, Docker now runs on Windows and MacOS as well. To understand how Docker works, let’s take a look at some of the components you would use to create Docker-containerized applications.

Docker architecture

No alt text provided for this image

Docker uses a client-server architecture. The Docker?client?talks to the Docker?daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon?can?run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface. Another Docker client is Docker Compose, that lets you work with applications consisting of a set of containers.

Docker Commands

  1. Lifecycle Commands
  2. Starting and Stopping Containers
  3. Docker Image Commands
  4. Docker Container And Image Information
  5. Network Commands
  6. Lifecycle Commands

Lifecycle Commands

  • Create a container (without starting it):

docker create [IMAGE]        

  • Rename an existing container

docker rename [CONTAINER_NAME] [NEW_CONTAINER_NAME]        

  • Run a command in a new container

docker run [IMAGE] [COMMAND]        

  • Remove container after it exits

docker run --rm [IMAGE]        

  • Start a container and keep it running

docker run -td [IMAGE]        

  • Start a container and creates an interactive bash shell in the container

docker run -it [IMAGE]        

  • Create, Start, and run a command inside the container and remove the container after executing command.

docker run -it-rm [IMAGE]        

  • Execute command inside already running container.

docker exec -it [container]        

  • Delete a container (if it is not running)

docker rm [CONTAINER]        

  • Update the configuration of the container

docker update [CONTAINER]        

Starting and Stopping Containers

  • Start Container

docker start [CONTAINER]        

  • Stop running Container

docker stop [CONTAINER]        

  • Stop running Container and start it again

docker restart [CONTAINER]        

  • Pause processes in a running container

docker pause [CONTAINER]        

  • Unpause processes in a running container

docker unpause [CONTAINER]        

  • Block a container until others stop

docker wait [CONTAINER]        

  • Kill a container by sending a SIGKILL to a running container

docker kill [CONTAINER]        

  • Attach local standard input, output, and error streams to a running container

docker attach [CONTAINER]        

Docker Image Commands

  • Create an image from a Dockerfile

docker build [URL/FILE]        

  • Create an image from a Dockerfile with Tags

docker build -t <tag> [URL/FILE]        

  • Pull an image from a registry

docker pull [IMAGE]        

  • Push an image to a registry

docker push [IMAGE]        

  • Create an image from a tarball

docker import [URL/FILE]        

  • Create an image from a container

docker commit [CONTAINER] [NEW_IMAGE_NAME]        

  • Remove an image

docker rmi [IMAGE]        

  • Load an image from a tar archive or stdin

docker load [TAR_FILE/STDIN_FILE]        

  • Save an image to a tar archive

docker save [IMAGE] > [TAR_FILE]        

Docker Container And Image Information

  • List running containers

docker ps        

  • Lists both running containers and ones that have stopped

docker ps -a        

  • List the logs from a running container

docker logs [CONTAINER]        

  • List low-level information on Docker objects

docker inspect [OBJECT_NAME/ID]        

  • List real-time events from a container

docker events [CONTAINER]        

  • Show port mapping for a container

docker port [CONTAINER]        

  • Show running processes in a container

docker top [CONTAINER]        

  • Show live resource usage statistics of container

docker stats [CONTAINER]        

  • Show changes to files (or directories) on a filesystem

docker diff [CONTAINER]        

  • List all images that are locally stored with the docker engine

docker [image] ls        

  • Show the history of an image

docker history [IMAGE]        

Network Commands

  • List networks

docker network ls        

  • Remove one or more networks

docker network rm [NETWORK]        

  • Show information on one or more networks

docker network inspect [NETWORK]        

  • Connects a container to a network

docker network connect [NETWORK] [CONTAINER]        

  • Disconnect a container from a network

docker network disconnect [NETWORK] [CONTAINER]        
No alt text provided for this image

Thank You For your Time....!!!!


要查看或添加评论,请登录

Sandeep Kumar Patel的更多文章

社区洞察

其他会员也浏览了