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

Docker Practice Commands

This document provides an overview of basic Docker commands for working with images, containers, and Docker Hub. It includes commands to build, run, stop, delete images and containers, as well as commands to log in to Docker Hub and publish images.

Uploaded by

ge.anand
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Docker Practice Commands

This document provides an overview of basic Docker commands for working with images, containers, and Docker Hub. It includes commands to build, run, stop, delete images and containers, as well as commands to log in to Docker Hub and publish images.

Uploaded by

ge.anand
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#######################################

Basics
#######################################
# Get docker version
docker --version

# Get docker system-wide info


docker info

#Start docker daemon


docker -d

#Get help
docker --help

#######################################
IMAGES
#######################################

# Get all images on local computer


docker images

# Download new docker images from Docker Hub


docker pull <image-name>[:tag]

# Search for docker images on Docker Hub


docker search <image-name>

# Delete an image
docker rmi <image_name>

#Build an image from a Dockerfile - must be in same folder in which command is


being executed
docker build -t <image_name> .

#Build an Image from a Dockerfile without the cache - must be in same folder in
which command is being executed
docker build -t <image_name> . –no-cache

#Remove all unused images


docker image prune
#######################################
CONTAINERS
#######################################
#Get all containers
docker container list

#Get all running containers


docker ps

# Get all running and stopped containers


docker ps -a

#Create and run a container


docker run --name <container_name> <image_name>

#Run a container in the background


docker run -d <image_name>
#Start or stop an existing container
docker start|stop <container_name> (or <container-id>)

#Remove a stopped container


docker rm <container_name> (or container-id)

#Open a shell inside a running container:


docker exec -it <container_name> sh

### IMPORTANT AND USEFUL CONTAINER COMMANDS####

#Fetch and follow the logs of a container:


docker logs -f <container_name>

#To inspect a running container:


docker inspect <container_name> (or <container_id>)

#View resource usage stats


docker container stats

#######################################
# Docker hub
#######################################

#Connect to docker hub


docker login -u <user-name>

#Publish an image to docker hub


docker push <username>/<image-name>

You might also like