Docker Basics/Commands Cheatsheet

Yogesh Bali
4 min readNov 7, 2019

--

Docker is a platform where we can develop, run, deploy the software applications.

Docker is lightweight as it not includes the load of hypervisor (hence not includes the heavy OS images).

A host machine can have more docker containers than the number of VMs inside.

Docker provides the ability to package and run an application in a loosely isolated environment called a container.

A docker container hence will contain your software application + infrastructure required for that software application.

Docker image is set of instructions for creating the docker container.

Docker Image is created using the docker file or docker commands.

Docker Engine consists of three components:

  • Docker command line interface.
  • Rest API
  • Docker server called docker daemon.

Installing Docker toolbox-

  1. Windows 7 OS : Docker Toolbox.
    Download it from here — https://docs.docker.com/v17.12/toolbox/toolbox_install_windows/

Docker Toolbox includes the following Docker tools:

  • Docker CLI client for running Docker Engine to create images and containers
  • Docker Machine so you can run Docker Engine commands from Windows terminals
  • Docker Compose for running the docker-compose command
  • Kitematic, the Docker GUI
  • The Docker QuickStart shell preconfigured for a Docker command-line environment.
  • Oracle VM VirtualBox.

2. Windows 10 Professional/Mac: Docker Desktop.

Download it from here — https://hub.docker.com/?overlay=onboarding

Docker hub

Docker hub is a docker repository to download the docker images:

URL: https://hub.docker.com/

Basic Docker commands:

  1. docker help: This will list the commands and their description.

Commands:

docker help

docker container --help

2) docker search : Allows you to search docker images on docker hub.

docker search <image_name>

Example: docker search ubuntu.

Try to use images which are official ok and having more stars.

3) docker create: Creates a new container.

docker create — name=foo -it ubuntu bash (it — interactive)

Here we are creating an image of ubuntu. And passing the command bash.

Image is created locally.

4) Start docker container : It starts one or more stopped containers

docker start <container_name or id>

Example: docker start foo

5) docker container ls: List containers that are created and having status up.

6) docker container ls -a: List all the containers. It will shows both containers in up state and in created state.

7) Command to List file system of host machine ($ ls).

How to list file system of container?

docker attach <container_name or id>

Docker Attach command attach local standard input, output, and error streams to a running container.

Now prompt changes from $ to #. It means now we are inside the container. Now command typed will be executed inside container.

#ls command will list files of inside the list container.

8) docker logs <container_name or id>: Fetch the logs of the container

9) Stop one or more running containers:

docker stop <container_name or id>

10) Removing docker container: Note You cannot remove a running container. So first you need to stop/kill that container. Command for remove

docker rm <container_name or id>

rm -f : If you want to remove running container, use remove force command:

11) docker run: It runs a command in a new container. Creation of container, starting of it and attachment of command in a new container.

12)

--

--

Yogesh Bali
Yogesh Bali

Written by Yogesh Bali

Senior Technical Lead in Thales

Responses (1)