DEV Community

Cover image for Deploy a Grafana dashboard with Docker on AWS EC2
Matteo Barbero
Matteo Barbero

Posted on

Deploy a Grafana dashboard with Docker on AWS EC2

Monitoring system performance and logs with Grafana is indeed straightforward, especially when working with Docker environments. Grafana seamlessly integrates with Docker, providing prebuilt dashboards that instantly visualize key metrics and logs from your containers and hosts.

Launch EC2 instance

To embark on your AWS journey, you'll need a server instance, and AWS offers the perfect playground with its free tier. Launch a Linux instance effortlessly, and let the experimentation begin!

Click on launch EC2 instance and select t2.micro to use the free tier.

Launch EC2 Dashboard

Here we need some more configurations:

  • Create a key pair (for the login) and download it in a safe place;
  • Add a security group or create a new one; -Allow traffic from both ssh and internet.

Now you can launch your EC2 instance

Open ports

For these project we need to open these ports:

  • 3000 for Grafana
  • 9090 for Prometheus
  • 3100 for Loki
  • 9100 for node-exporter

EC2 port settings

To do this:

  • navigate to the EC2 Dashboard and select your EC2 instance
  • click on the security group associated and the click edit
  • configure the inbound rule selecting Custom TCP Rule as the type. Enter the port number and select Anywhere as the source.
  • Repeat the last step for all the four ports

Install Docker

With your Linux instance up and running, it's time to unlock the power of containerization by installing Docker. This game-changing platform will enable you to effortlessly deploy and manage your applications, including the highly coveted Grafana dashboard.

Connect via ssh

In your terminal run

ssh -i "<path_to_your_key.pem>" ec2-user@<Public IPv4 DNS>
Enter fullscreen mode Exit fullscreen mode

Type yes and you are inside your instance!

SSH Connection

Install Docker and Docker Compose

To install Docker run:

sudo yum update
sudo yum install -y docker
Enter fullscreen mode Exit fullscreen mode

Then we can install Docker Compose. Run:

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

Run Docker service

If everything since here went fine you only need to start the Docker daemon. To do this run:

sudo systemctl start docker
sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode

Copy the project

You can download the source code from the repo and copy it into the EC2 with scp, or clone directly into the EC2 instance, and check if git is installed.

To clone the repo run:

git clone https://github.com/maiobarbero/grafana-prometheus-loki.git
Enter fullscreen mode Exit fullscreen mode

Edit the configuration's files

Now with vim edit the configuration file, in particular if you are using this repository edit config/prometheus/prometheus-config.yml and replace localhost with your private IP4.

Run the application

Here we are, the last step. Inside your project folder run

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

And that's it.

Go to your-public-ip:3000 and you have your Grafana instance!!!


Cover image by Chris Liverani on Unsplash

Top comments (0)