Quick Command References: Docker Container

A summary of commonly used docker commands.

Docker Image Management


Check the images on your host:

docker image ls

Search images from the Docker hub

docker search <name_to_search>


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> .


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?

Leave a Reply

Your email address will not be published.