100DaysOfCode — Day 05
Tags: docker, kubernetes, 100daysofcode
Published: 2021-02-13 22:44:56

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9cuoc13sybyj26dhip38.jpg)

In this series, I will alternate between Go language learning, Docker concepts, and Kubernetes.

Today, I finished a basic docker tutorial. I am glad to share it with you.

### Prerequisite
1. Install docker
 * [Install Docker Desktop on Mac] (https://docs.docker.com/docker-for-mac/install/)
 * [Install Docker Desktop on Windows] (https://docs.docker.com/docker-for-windows/install/)

### What is a container?
Docker provides the ability to package and run an application in a loosely isolated environment called a container. A container is simply another process on your machine that has been isolated from all other processes on the host machine.

### Your first container
Open a command prompt or bash window, and run the command:
```bash
$ docker run -dp 80:80 --name getting-started docker/getting-started
```
 * `docker run` Run a command in a new container
 * `-d` Run container in background and print container ID
 * `-p 80:80` Publish a container's port(s) to the host
 * `docker/getting-started` Docker image to run
 * `--name getting-started` Assign a name to the container

### Test your container
```bash
$ docker ps
```
 * `docker ps` List containers

You see a list like this shows a container running docker/getting-started image.
```bash
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                NAMES
1af9e7993c08   docker/getting-started   "nginx -g 'daemon of…"   2 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp   getting-started
```
Now open your browser and go to `http://localhost/`. Boom ... your container is up and running:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4xw02r47aupw5pwvvpnx.png)

### End the container
Now run the following command to end the container:
```bash
$ docker stop getting-started
```
Now list the containers
```bash
$ docker ps
```
```
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
```

Note that docker container has stopped but it is still in your system. You can see stopped containers using the following command:
```bash
$ docker ps -a
```
You will see this:
```bash
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                     PORTS     NAMES
1af9e7993c08   docker/getting-started   "nginx -g 'daemon of…"   6 minutes ago    Exited (0) 3 minutes ago             getting-started
```

To remove the container run the following command:
```bash
$ docker rm getting-started
```
```bash
$ docker ps -a
```

### Remove the image
Note that `docker/getting-started` image was downloaded when ran `docker run` command. Run the following command to see image in your system:
```bash
$ docker images
```
```bash
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
docker/getting-started        latest    3c156928aeec   9 months ago    24.8MB
```

Run the following command to remove the downloaded image:
```bash
$ docker rmi docker/getting-started
```
```
Untagged: docker/getting-started:latest
Untagged: docker/getting-started@sha256:d2c4fb0641519ea208f20ab03dc40ec2a5a53fdfbccca90bef14f870158ed577
Deleted: sha256:3c156928aeec9595a140d3e9bb67fc6849650a0a756bbb0b1690ce9a4ddca884
Deleted: sha256:bd0923edebaabd47c31d4f79115f9cbd91e6045c9b2585f02b346af81a6d3dbd
Deleted: sha256:0d6528f3488cda7f74d825579182af56cbdd7fed5bccacfa3042834b514157ac
Deleted: sha256:ec7d8444b0ff84cd1e55ec191abe60e26f996ac883d87dcb50fdca507f2af8be
Deleted: sha256:beee9f30bc1f711043e78d4a2be0668955d4b761d587d6f60c2c8dc081efb203
```


End of day 5 of 100DaysOfCode.