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.

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:
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:
sudo reboot
After your instance has rebooted, log in as the dockeruser and run the following command to start the nginx container:
docker run --name my-nginx-container -p 80:80 -d nginx

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.

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.

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:

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

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.

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.



