Certainly, here's a complete set of commands to install Docker and set up Jenkins using Docker on an Amazon Linux 2 instance in AWS:
Step 1: Update the Package Repository
sudo yum update -y
Step 2: Install Docker
sudo yum install docker -y
Step 3: Start and Enable the Docker Service
sudo service docker start
service docker status
Step 4: Add Your User to the Docker Group
sudo usermod -a -G docker ec2-user
Step 5: Log Out and Log Back In (or use su)
su - ec2-user
Step 6: Verify Docker Installation
docker --version
Step 7: Pull and Run Jenkins Docker Container
docker pull jenkins/jenkins
docker run -d -p 8080:8080 -p 50000:50000 jenkins/jenkins
Step 8: Access Jenkins
-
Find the public IP address of your AWS EC2 instance:
curl http://checkip.amazonaws.com
-
Open a web browser and go to
http://<Your-EC2-Public-IP>:8080
. You will be prompted to unlock Jenkins.
-
Retrieve the initial admin password by running the following command on your EC2 instance:
docker exec $(docker ps -q --filter "ancestor=jenkins/jenkins") cat /var/jenkins_home/secrets/initialAdminPassword
This command will display the initial admin password. Copy it.
-
Paste the initial admin password into the Jenkins web interface to unlock Jenkins.
Step 9: Jenkins Setup
-
Follow the Jenkins setup wizard to install recommended plugins and create an admin user.
-
Once the setup is complete, you can start using Jenkins to create and manage your CI/CD pipelines.