0

Docker Common Commands: 101 Part 2

The comprehensive Docker command line reference is located here. However we will cover some basic commands.

Image
Build an imagedocker build -rm=true .
Install an imagedocker pull ${IMAGE}
List of installed imagesdocker images
docker images --tree (tree view)
docker images -no-trunc (detailed listing)
Remove an imagedocker rmi ${IMAGE_ID}
Remove all untagged imagesdocker rmi $(docker images | grep "^" awk '{ print $3 }')
Remove all imagesdocker rm $(docker ps -aq)
Container
Run a containerdocker run (many other options on this)
List containersdocker ps
docker ps -a (list all containers)
Stop a containerdocker stop ${CID}
Restart a containerdocker restart ${CID}
Find IP address of containerdocker inspect --format ‘{{ .NetworkSettings.IPAddress }}’ ${CID}
Attach to a containerdocker attach ${CID}
Remove a containerdocker rm ${CID}
Remove all containersdocker rm $(docker ps -aq)
Find CID of last-run containerdocker ps -l -q
Copy a file in a container to hostdocker cp ${CID}:/etc/passwd .
Show container informationdocker inspect ${CID}
Show logs of a containerdocker logs ${CID}
Show running process in a containerdocker top ${CID}
Mount a directory in host to a containerdocker run -v /host/dir:/container/dir ${CID}
Commit locallydocker commit ${CID} ${image_name}
Push to regiserydocker push repo_name
repo_name = [docker_username]/[docker_image_name]

 

Export/Save/Import - what is the difference?
EXPORT - is used to persist a container (NOT AN IMAGE) and will use ${CID}. Please note that the EXPORT is slightly smaller since it is flattened - history and meta-data is removed. A running container can be exported.

docker ps -a
docker export ${CID} > /export/exported.tar

SAVE - is used to persist an image (NOT A CONTAINER)

docker images
docker save testimage > /export/testimage.tar

IMPORT:
--container import

cat /export/exported.tar | docker import - exported:latest
docker images
docker run exported

--image import

docker load < /export/testimage.tar docker images docker run testimage

jlim0930

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.