Docker is awesome.
Tags: docker, tools
Published: 2022-11-13 11:41:19

---
title: Docker is awesome.
published: true
tags: [
    "Docker",
    "Tools"
]
canonical_url: https://blog.arisamiga.rocks/post/docker/
---

![Docker](https://blog.arisamiga.rocks/img/docker.png)

## So. What is Docker?

Docker is a tool that allows you to run applications in a containerized environment. It is a great tool for developers and sysadmins as it allows you to run applications in a sandboxed environment that is isolated from the host system. This allows you to run multiple applications in the same system without having to worry about conflicts between them.


Docker allows you to run an application in something called a "Container" which is an environment that is isolated from the host system. It is especially useful in cases where you need to have libraries or packages with different versions in the same system.

## How does it work?

Docker is started by creating a Dockerfile which is a file that contains the instructions for building the container. The Dockerfile is then used to build the container which is then run by the Docker daemon. *(The Docker daemon is a service that runs in the background and is responsible for running the containers.)*
```dockerfile
# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
```

Instead of a Dockerfile, you are able to also use a Docker image which is a pre-built container that you can use. Each image is made for specific purposes and is usually made by the community at [Docker Hub](https://hub.docker.com/).

![Docker Hub](https://blog.arisamiga.rocks/img/docker-hub.png)

When a container is run using [`docker run`](https://docs.docker.com/engine/reference/run/) it is then given a name and a unique ID. The name is used to identify the container and the ID is used to identify the container in the Docker daemon. By also using the [`-d`](https://docs.docker.com/engine/reference/commandline/run/#options) flag, the container is run in the background and is not attached to the terminal.

![Docker Number and ID](https://blog.arisamiga.rocks/img/docker-container.png)

You can look at running containers using [`docker ps`](https://docs.docker.com/engine/reference/commandline/ps/) and you can look at all containers using [`docker ps -a`](https://docs.docker.com/engine/reference/commandline/ps/) which will show even exited ones.

## Docker commands

Here are some of the most common commands that you will use when working with Docker.

### docker run

The [`docker run`](https://docs.docker.com/engine/reference/run/) command is used to run a container. It takes the name of the image that you want to run as an argument. You can also specify the name of the container using the `--name` flag. If you don't specify a name Docker will generate a random name for you.

```bash
docker run --name my-container my-image
```

### docker ps

The [`docker ps`](https://docs.docker.com/engine/reference/commandline/ps/) command is used to list running containers. You can also use the `-a` flag to list all containers.

```bash
docker ps
```

### docker stop

The [`docker stop`](https://docs.docker.com/engine/reference/commandline/stop/) command is used to stop a running container. It takes the name of the container as an argument.

```bash
docker stop my-container
```

### docker start

The [`docker start`](https://docs.docker.com/engine/reference/commandline/start/) command is used to start a stopped container. It takes the name of the container as an argument.

```bash
docker start my-container
```

### docker rm

The [`docker rm`](https://docs.docker.com/engine/reference/commandline/rm/) command is used to remove a container. It takes the name of the container as an argument.

```bash
docker rm my-container
```

### docker exec

The [`docker exec`](https://docs.docker.com/engine/reference/commandline/exec/) command is used to execute a command in a running container. It takes the name of the container as an argument and the command that you want to execute.

```bash
docker exec my-container ls
```

### docker build

The [`docker build`](https://docs.docker.com/engine/reference/commandline/build/) command is used to build a container from a Dockerfile. It takes the path to the Dockerfile as an argument.

```bash
docker build .
```

### docker pull

The [`docker pull`](https://docs.docker.com/engine/reference/commandline/pull/) command is used to pull an image from Docker Hub. It takes the name of the image as an argument.

```bash
docker pull my-image
```

### docker push

The [`docker push`](https://docs.docker.com/engine/reference/commandline/push/) command is used to push an image to Docker Hub. It takes the name of the image as an argument.

```bash
docker push my-image
```

Docker is a pretty amazing tool to use and is especially useful when working with multiple applications and I couldn't recommend it enough. 

Here is also an amazing Tutorial by Programming with Mosh that you can watch to learn more about Docker!

{% youtube pTFZFxd4hOI %}