# Day 18 : Exploring Docker: Running, Inspecting, and Managing Containers

Today we have 4 tasks to perform and to explore docker. Let's start.

Task 1 : Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine. Run the container as a non-root user (Hint- Use `usermod` command to give user permission to docker). Make sure you reboot instance after giving permission to user.

The first step is to pull a pre-existing Docker image from a public repository. In this tutorial, we'll be using the `nginx` image.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683912052229/bb9ef5a5-3a35-4e1c-9d58-423b3adfdd75.png align="center")

By default, Docker containers run as the root user. However, it's not recommended to run containers as root, as this can be a security risk. Instead, you should run containers as a non-root user.

To do this, you need to create a new user on your local machine and give them permission to access Docker. You can do this by using following command:

```bash
sudo useradd -m dockeruser
sudo usermod -aG docker dockeruser
```

After running this command, you need to reboot your instance to apply the changes. You can do this by running the following command:

```bash
sudo reboot
```

After your instance has rebooted, log in as the `dockeruser` and run the following command to start the `nginx` container:

```bash
docker run --name my-nginx-container -p 80:80 -d nginx
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683912426457/5a0800bb-f19d-4372-8908-79b917787b1e.png align="center")

This command creates a new Docker container named `my-nginx-container`, maps port 80 of the container to port 80 on your machine, and runs the `nginx` image in the container.

Task 2 : Inspect the container's running processes and exposed ports using the docker inspect command.

To inspect the container's running processes and exposed ports, you can use the `docker inspect` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683912575127/662981e7-6782-431f-bfc4-144df047a0eb.png align="center")

This command displays a JSON object that contains information about the container, including its running processes, exposed ports, and more.

Task 3 :Use the docker logs command to view the container's log output.

To view the container's log output, you can use the `docker logs` command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683912677885/a7585e83-5a68-4994-9731-673b0eac63d2.png align="center")

Task 4 : Use the docker stop and docker start commands to stop and start the container.

To stop the nginx container we just started, we can run the following command in a terminal:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683912787028/e38bd0f7-7ec6-4484-8e0f-dddfd930d215.png align="center")

To start the container again, we can run the following command in a terminal:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683912843072/7e485680-5120-41ff-84fa-6cd17641a7cd.png align="center")

Task 5 : Use the docker rm command to remove the container when you're done.

The docker rm command is used to remove a container from your system. This can be useful when you no longer need a container, or when you need to free up disk space.

Make sure you stop container before removing it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683913014901/24e11ac0-316a-4f26-a310-c0c544a9fedc.png align="center")

And that's it! We've now completed all tasks for Day 18. I hope screenshots will help you to understand commands. See you on another day with another challenges.

Happy coding.
