Exercise Basic Docker Commands

Let us Start

Table of Contents

Install docker on amazon linux

Instructions on how to install Docker on Amazon Linux:

Update the installed packages and package cache on your instance

yum update -y

Install the most recent Docker Community Edition package

yum install docker -y 

Start the Docker service

service docker start

Add the ec2-user to the docker group so you can execute Docker commands without using sudo

usermod -a -G docker ec2-user

Verify the docker version

Show the Docker Version, how to check the installed version of Docker:

Check Docker version

docker --version

Search for Docker images on Docker Hub using the docker search command. For example, to search for Ubuntu images:

Search for Ubuntu images

docker search ubuntu

How to run a container from an image

Run a container

docker run -it ubuntu:latest /bin/bash

Listing Containers

List all running containers

docker ps

List all containers, even those not running

docker ps -a

List all container IDs

docker ps -q

How to stop a container

Stop a container

docker stop <container_id>

How to remove a container

Remove a container

docker rm <container_id>

Remove all containers

docker rm $(docker ps -aq)

Last updated