Get started with Docker with these 10 commands

Get started with Docker with these 10 commands

Prerequisites

  • Docker installed on the System

Introduction

Developing apps today requires so much more than writing code. Multiple languages, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage creates enormous complexity. Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project

-- Docker

docker2.png

Commands

0. Check Docker version

docker --version

image.png


1. To search for an image on the docker-hub registry

docker search <image_name>:<tag>

image.png


2. To pull an image from the docker-hub registry

docker pull <image_name>:<tag>

image.png


3. Running a docker container

docker run --name <name> -d -p <host_OS_port>:<application_port> <image_name>:<tag>
  • -d : to run the container in detached mode
  • --name : to give a customized name to the running container
  • -p : to define the port on the Host OS in order to access the container port

image.png


4. Seeing the running containers

docker ps

Or

docker container ls

Using docker ps -a we can get the information about containers whether they are running or stopped

image.png


5. Checking the images on the local machine

docker image ls

image.png


6. Stopping running containers

docker stop <container_name OR container_ID>

image.png

image.png


7. Starting stopped containers

docker stop <container_name OR container_ID>

image.png

image.png


8. Removing stopped containers

docker stop <container_name OR container_ID>

image.png


9. Running commands inside the containers

docker exec -it <container_name OR container_ID> bash
  • -i : to run an interactive shell
  • -t : to activate pseudo-tty

image.png


10. Get low-level information about containers

docker inspect <container_name OR container_ID> bash

image.png


Congratulations on getting started with Docker. Now go ahead and build and deploy on Docker

Useful Link: Docker Guides