환경 셋업
개인 EC2 생성
- 이름 : junseok-curriculum
- AMI : Ubuntu 22.04
- 인스턴스 유형 : t3.micro
- 키 페어 : junseok-key
- VPC : default-vpc
- 보안 그룹 : junseok-sg
SSH 접속 확인
MobaXterm SSH 접속

정상 접속 확인

Docker
Docker 설치
설치
curl -s https://get.docker.com | sudo sh
권한 부여
sudo usermod -aG docker $USER
Dockerfile 생성
- Ubuntu 20.04 버전
- ~./bashrc에 TEST는 LJS 라는 환경 변수 추가
- aws-cli 2버전대 설치
- python3.7 버전 설치
- vim 설치
vi Dockerfile
FROM ubuntu:20.04
# Set environment variable
RUN echo 'export TEST=LJS' >> ~/.bashrc
# Install dependencies
RUN apt-get update && \
apt-get install -y curl unzip software-properties-common
# Install Python 3.7
RUN add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y python3.7
# Install additional packages
RUN apt-get install -y curl unzip vim
# Install AWS CLI
RUN curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install && \
rm awscliv2.zip && \
rm -rf aws
# Set Python 3.7 as the default python3
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
# Clean up
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Set default command
CMD ["bash"]
Docker Image 생성
build, run 쉘 스크립트 작성
vi docker.sh
#!/bin/bash
docker build -t junseok-curriculum .
docker run -it junseok-curriculum
실행 권한 부여
sudo chmod +x docker.sh
실행
./docker.sh
Jenkins 설치
Dockerfile에 Jenkins 설치 코드 추가
FROM ubuntu:20.04
# Set environment variable
RUN echo 'export TEST=LJS' >> ~/.bashrc
# Install dependencies
RUN apt-get update && \
apt-get install -y curl unzip software-properties-common
# Install Python 3.7
RUN add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y python3.7
# Install additional packages
RUN apt-get install -y curl unzip vim
# Install AWS CLI
RUN curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install && \
rm awscliv2.zip && \
rm -rf aws
# Install OpenJDK 11
RUN apt-get install -y openjdk-11-jre
# Download Jenkins war file
RUN mkdir /opt/jenkins && \
curl -L http://mirrors.jenkins.io/war-stable/latest/jenkins.war -o /opt/jenkins/jenkins.war
# Set Python 3.7 as the default python3
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
# Clean up
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Set default command to run Jenkins in the background
CMD ["java", "-jar", "/opt/jenkins/jenkins.war"]
jenkins 설치에 따른 docker.sh 수정
#!/bin/bash
docker build -t junseok-curriculum .
docker run -d -p 80:8080 junseok-curriculum
8080 포트 사용을 위한 보안그룹 인바운드 규칙 추가
초기 비밀번호 확인을 위한 docker.sh 수정
#!/bin/bash
docker build -t junseok-curriculum .
docker run -d -p 80:8080 --name jenkins junseok-curriculum
sleep 10
docker exec -it jenkins cat /root/.jenkins/secrets/initialAdminPassword