Setting Up Grafana Dashboard with Docker
Prerequisites
Ensure Docker is installed on your system. If not, install Docker from the official Docker website.
Step-by-Step Instructions
1. Create a Docker Volume for Persistent Storage
Grafana stores its data (such as dashboards, configurations, and plugins) in a persistent volume to ensure that data is not lost when the container is stopped or removed.
docker volume create grafana-data

2. Run the Grafana Docker Container
Now, you can run the Grafana container. This command will start Grafana and map port 3000 on your host to port 3000 on the container, making Grafana accessible via http://localhost:3000
.
docker run -d --name=grafana -p 3000:3000 -v grafana-data:/var/lib/grafana grafana/grafana:latest

Breakdown of the Command
docker run
: Command to run a new container.-d
: Run the container in detached mode (in the background).--name=grafana
: Assign a name to the container.-p 3000:3000
: Map port 3000 of the host to port 3000 of the container.-v grafana-data:/var/lib/grafana
: Mount the Docker volumegrafana-data
to/var/lib/grafana
inside the container. This ensures that Grafana's data is stored persistently.grafana/grafana:latest
: Specifies the Docker image to use, withlatest
indicating the latest version.
If it is successful, it will look like this in your Docker container:

3. Access Grafana
Once the container is running, you can access the Grafana web interface by opening a web browser and navigating to: http://localhost:3000
4. Log In to Grafana
The default username is
admin
.The default password is
admin
.
You will be prompted to change the default password upon first login for security reasons.

5. Configure Grafana
After logging in, you can start configuring Grafana by adding data sources, creating dashboards, and installing plugins as needed.
Additional Tips
Restarting Grafana
If you need to restart the Grafana container, use the following command:
docker restart grafana
Stopping and Removing the Grafana Container
To stop the Grafana container, use:
docker stop grafana
To remove the Grafana container, use:
docker rm grafana
Updating Grafana
To update Grafana to the latest version, first remove the existing container:
docker rm -f grafana
Then, pull the latest image and run the container again:
docker pull grafana/grafana:latest
docker run -d --name=grafana -p 3000:3000 -v grafana-data:/var/lib/grafana grafana/grafana:latest