Sunday, October 17, 2021

Basic Docker Commands

 Trying to list some Docker commands:

1. docker run 

Run a container from an image

2. docker run nginx

Will run an instance of the nginx application on the docker host.

3. docker ps

Lists all running containers

4. docker ps -a

Will list all containers (running, stopped and exited ones)

5. docker stop <id or name>

Stops a container

6. docker rm <id or name>

Remove stopped or exited containers

7. docker images

List of images on the host

8. docker rmi <image name>

To remove an image.

9. docker pull <imagename>

Pulls an image. Logically if the image is not present and if we run a `docker run` command, it will pull the image if not found locally. This takes time and we can pull and keep an image locally if needed.

10. docker run <repository name>

Runs in the foreground

11. docker run -d <repository name>

Runs in the background.

12. docker attach <container ID>

This is used to attach to a container running in the background. To get the ID, use the `docker ps` command.



Introduction to Docker

 Before we learn about Docker, let's try to understand some basics.

What is a container?

A container is an isolated environment, having their own processes and services (just like a VM), but they share the same OS kernel.

Docker is used to containerise applications and run them anywhere. 

Ah! So Docker is same as a VM (Virtual Machine)?

No! Refer image before for Docker vs VM



A Virtual Machine (VM) has its own OS. Hence, it would be more heavy and size would be in GBs.

Docker containers would be less heavy (MBs in size). Hence, docker containers boot up much faster.

Since VMs don't rely on the underlying OS, they are more isolated than docker containers.

Docker and VMs:

In large environments, we will often see docker containers provisioned on VM hosts.



Previously we may have a VM per application. In above case, we now have a VM containing many docker containers and hence # of VMs will reduce.

Where can we see list of images available?