A summary of commonly used docker commands.
Docker Image Management
Search/List
Check the images on your host:
docker image ls
Search images from the Docker hub
docker search <name_to_search>
Create/Pull
To pull an image from the Docker hub
docker pull ubuntu:18.04
To create a custom image, create a Dockerfile
FROM ubuntu:18.04 RUN apt-get update && apt-get install -y git python vim CMD cd ~
To build an image from the above Dockerfile
docker build -t <image_name>:<tag_name> .
Delete
To delete an existing image on the host
docker image rm <image_name>:<tag_name>
Container Management
To create and run a container from an image
docker run -it <image_name>:<tag_name> /bin/bash
To mount a directory from the host onto a specified path while creating/running a container:
docker run -it -v <host_dir_path>:<container_path> -w <container_path> <image_name>:<tag_name> /bin/bash # Example: # docker run -it -v `pwd`:/root/mytest -w /root/mytest python:latest /bin/bash
where -w specifies the working directory where the container should eneter once running.
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.