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 image docker build -rm=true .
Install an image docker pull ${IMAGE}
List of installed images docker images
docker images –tree (tree view)
docker images -no-trunc (detailed listing)
Remove an image docker rmi ${IMAGE_ID}
Remove all untagged images docker rmi $(docker images | grep “^” awk ‘{ print $3 }’)
Remove all images docker rm $(docker ps -aq)
Container
Run a container docker run (many other options on this)
List containers docker ps
docker ps -a (list all containers)
Stop a container docker stop ${CID}
Restart a container docker restart ${CID}
Find IP address of container docker inspect –format ‘{{ .NetworkSettings.IPAddress }}’ ${CID}
Attach to a container docker attach ${CID}
Remove a container docker rm ${CID}
Remove all containers docker rm $(docker ps -aq)
Find CID of last-run container docker ps -l -q
Copy a file in a container to host docker cp ${CID}:/etc/passwd .
Show container information docker inspect ${CID}
Show logs of a container docker logs ${CID}
Show running process in a container docker top ${CID}
Mount a directory in host to a container docker run -v /host/dir:/container/dir ${CID}
Commit locally docker commit ${CID} ${image_name}
Push to regisery docker 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. Required fields are marked *

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