简体   繁体   中英

Dockerfile - install jenkins on AWS

New to AWS so any help would be appreciated.

I'm attempting to run Jenkins through Docker on AWS. I found this article https://docs.aws.amazon.com/aws-technical-content/latest/jenkins-on-aws/containerized-deployment.html

Can anyone share a better step-by-step tutorial to achieve this? the page above seems incomplete.

It talks about "The Dockerfile should also contain the steps to install the Jenkins Amazon ECS plugin" but does not show how to go about installing the plugin using the Dockerfile.

thanks

Please follow below steps:

  1. Launch EC2 cluster according to your needs.
  2. Install docker in you local machine. For example, for ubuntu ( sudo apt-get isntall docker.io )
  3. systemctl start docker
  4. Create new folder for our jenkins docker. Create new Dockerfile inside it with following contents. FROM Jenkins COPY plugins.txt /usr/share/jenkins/plugins.txt RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
  5. Create plugins.txt in same folder and add below line amazon-ecs:1.3
  6. Login to ECR using aws cli. Configure aws first with your credentials. aws ecr get-login --region <REGION> Run the output returned from above command to docker login.
  7. sudo docker build -t jenkins_master .
  8. sudo docker tag jenkins_master:latest <AWS ACC ID>.dkr.ecr.<REGION>.amazonaws.com/jenkins_master:latest
  9. Create repository in ECR for this image aws ecr create-repository --repository-name jenkins_master
  10. Push the image in AWS ECR. sudo docker push <AWS ACC ID>.dkr.ecr.<REGION>+.amazonaws.com/jenkins_master:latest
  11. Our Jenkins docker image is ready. But data stored by this Jenkins server will not be persistent. To store data permanently, we will create another docker image which will create a volume with mount point. For that, create new directory for this new docker image and inside it create another Dockerfile with below content. FROM Jenkins VOLUME ["/var/jenkins_home"]
  12. Again follow same commands to push this new repository to ECR. sudo docker build -t jenkins_dv . sudo docker tag jenkins_dv:latest <AWS ACC ID>.dkr.ecr.<REGION>.amazonaws.com/jenkins_dv:latest aws ecr create-repository --repository-name jenkins_dv sudo docker push <AWS Account Number>.dkr.ecr.<REGION>.amazonaws.com/jenkins_dv:latest
  13. Now our images are ready. We will use this images to run them as service on our ECS cluster. For that we need to install ecs-cli using below command for linux. sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
  14. Create a new txt file with below contents which will have jenkins configuration.
jenkins_master:
image: jenkins_master
cpu_shares: 100
mem_limit: 2000M
ports:
- "8080:8080"
- "50000:50000"
volumes_from:
- jenkins_dv
jenkins_dv:
image: jenkins_dv
cpu_shares: 100
mem_limit: 500M


15. Finally push this service using above file to your newly created cluster. ecs-cli compose --file docker_compose.txt service up --cluster <cluster_name>

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM