githubEdit

Install jenkins docker image with Terraform

Today we are going to install jenkins docker image with the help of terraform. Let's do it:

mkdir learn-terraform-docker-container
cd mkdir learn-terraform-docker-container
sudo nano main.tf

Let's create a terraform file to create the docker image of jenkins:

sudo nano main.tf
terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0.1"
    }
  }
}

provider "docker" {}

resource "docker_image" "jenkins" {
  name = "jenkins/jenkins:lts-jdk17"
}

resource "docker_container" "jenkins" {
  image = docker_image.jenkins.name
  name  = "jenkins_server"
  ports {
    internal = 8080
    external = 8080
  }
}

Now, init the terraform:

Format and validate the configuration

Now, check plan and apply

  • Prompt yes only your configuration is correct:

Tmux will be more helpful to you for testing:

  • ctrl + b and then press d to disattach the session

  • Later, you can also use

Your session will run on background.

Now access the public URL and here it goes:

Now, get the password; In my case:

Login this admin credentials:

Last updated