#Install docker in Centos/Rhel
$ yum install docker
#Check installed version of docker
$ docker -version
Container Lifecycle
#Create a container without starting it
$ docker create [IMAGE]
#Rename a container
$ docker rename [CONTAINER_NAME] [NEW_CONTAINER_NAME]
#Create and start a container
$ docker run [IMAGE]
#Remove a container after it stop
$ docker run --rm [IMAGE]
# Start a container and keep it running
$ docker run -itd [IMAGE]
#Create, start the container and run a command in it; remove the container after executing the command
$docker run -it -rm [IMAGE]
#Delete a container if it isn't running
$ docker rm [CONTAINER]
Image LifeCycle
#Create an image from a Dockerfile
$ docker build [URL]
#Build an image from a Dockerfile and tag it
$ docker build -t [URL]
#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 archieve as stdin
$ docker load [TAR_FILE/STDIN_FILE]
#Save an image to a tar archive stream to stdout with all parent layers,tags and versions
$ docker save [IMAGES] > [TAR_FILE]
Networking
#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]
#Connect a container to a network
$ docker network connect [NETWORK] [CONTAINER]
#Disconnect a container from a network
$ docker network disconnect [NETWORK] [CONTAINER]
Start & Stop
#Start a container
$ docker start [CONTAINER]
#Stop a running container
$ docker stop [CONTAINER]
#Stop a running container and start it up again
$ docker restart [CONTAINER]
#Pause processes in a running container
$ docker pause [CONTANIER]
#Unpause processes in a container
$ docker unpause [CONTAINER]
#Block a container until other container stop
$ docker wait [CONTAINER]
#Kill a container by sending SIGKILL to a running container
$ docker kill [CONTAINER]
#Attach local standard input, output, and error streams to a running container
$ docker attach [CONTAINER]
Information
# List running containers
$ docker ps
#List running and stopped containers
$ docker ps -a
#List the logs from a running container
$ docker logs[CONTAINER]
#List low-level information on an object
$ docker inspect [OBJECT_NAME/ID]
#List real time events from a container
$ docker events [CONTAINER]
#Show port (or specific) mapping from 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 all locally stored images
$ docker images
#Show history of an image
$ docker history [IMAGE]
0 Comments