1. EC2 서버 접속하기
EC2 서버에 접속하는 방법은 여러가지가 있다
본인이 git bash를 주로 사용하니까 git bash를 이용해 접속해본다
제공받은 pem 파일 경로 위에서 ubuntu 계정으로 접속할려면...
$ssh -i <pem 파일명.pem> ubuntu@<서버 도메인>
질문이 나오는데 Are you sure you want to continue connecting (yes/no/[fingerprint])?
yes 입력하면 된다
접속에 성공하면 git bash창이 다음과 같이 바뀐다

2. docker 설치하기
우분투 환경에서 docker를 설치하려면 공식문서에서 install using the repository 부분 그대로 따라하면 되겠다
https://docs.docker.com/engine/install/ubuntu/
Install Docker Engine on Ubuntu
docs.docker.com
2-1) set up the repository
apt 패키지 업데이트 후에 apt가 HTTPS를 넘어 repository를 사용할 수 있도록 패키지를 설치
$sudo apt-get update
공식문서에 \으로 연결되어있는데 한줄 띈다는 의미로 써진것 같다
근데 실제 명령어에는 \을 쓰면 에러남
https://askubuntu.com/questions/982029/unable-to-locate-package-have-i-done-something-wrong
Unable to locate package. Have I done something wrong?
I am installing docker in Ubuntu WSL on Windows 10 and I am using this command sudo apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
askubuntu.com

$sudo apt-get install ca-certificates curl gnupg lsb-release
그리고 docker의 공식 GPG key를 더해준다
당연히 아래 두줄은 위에거 한줄 입력하고 아래거 한줄 입력하고
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
다음 명령 한줄로 repository set up을 수행한다(두줄 아님)
근데 여기서는 중간에 \ 써도 먹히나보네..?
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2-2) install docker engine
apt 패키지를 업데이트해준다
$ sudo apt-get update
최신버전을 다음 명령어를 수행해서 다운받아준다
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
도커가 잘 설치되어 있는지 버전 확인
$ sudo docker -v
공식문서에서는 hello world image run 해보라는데
$ sudo docker run hello-world
3. jenkins 설치하기
EC2 서버에서 jenkins를 설치하려면 상당히 복잡하다.. linux인지 확인하고.. 자바 설치하고..
https://green-joo.tistory.com/12
AWS EC2(Amazon Linux 2)에 Jenkins 설치하기 ( AWS / EC2 / Linux / Jenkins ) _220713_업데이트
안녕하세요. 그린주입니다 ๑'ٮ'๑ 오늘도 힘차게 시작해보겠습니다! 개요 이번 글에서는 AWS EC2(Amazon Linux 2)에 Jenkins 설치하는 방법을 공유하고자 합니다. 참고로 JAVA가 설치되어있고 Jenkins 인바
green-joo.tistory.com
도커를 사용하는 이유가 또 여기에 있다
도커에서 jenkins 이미지를 다운받아 pull해서 run하기만 하면 바로 설치, 실행이 가능하다
https://gre-eny.tistory.com/345
[AWS] EC2의 Docker 위에 Jenkins Container 올리기
AWS EC2 Instance (Amazon Linux2) 에서 Docker로 Jenkins 이미지를 다운받아서 Container로 띄우는 것이 목표이다. ec2 인스턴스가 있다고 가정하고, Java나 Docker나 모두 설치되어 있다고 가정을 하고 시작한다. EC
gre-eny.tistory.com
https://hudi.blog/install-jenkins-with-docker-on-ec2/
EC2 환경에서 도커를 활용한 젠킨스 설치하기
이 글은 우아한테크코스 4기 달록팀의 기술 블로그에 게시된 글 입니다. 안녕하세요, 우테코 달록팀 후디입니다. 이번 스프린트에서는 저는 배포와 CI/CD와 같이 인프라와 관련된 태스크에 집중
hudi.blog
다음 명령을 통해 jenkins LTS 이미지를 다운받는다
$ docker pull jenkins/jenkins:lts
/var/run/docker.sock ~~ permission denied 에러가 날 수 있는데
일반사용자가 docker 명령어를 사용하려고 하면 에러 난다고함
https://github.com/occidere/TIL/issues/116
docker 설치 후 /var/run/docker.sock의 permission denied 발생하는 경우 · Issue #116 · occidere/TIL
docker 설치 후 /var/run/docker.sock의 permission denied 발생하는 경우 상황 docker 설치 후 usermod로 사용자를 docker 그룹에 추가까지 완료 후 터미널 재접속까지 했으나 permission denied 발생 (설치 참고: https://b
github.com
하나의 방법은 다음 명령을 사용하여 /var/run/docker.sock 파일 권한을 666으로 변경
$ sudo chmod 666 /var/run/docker.sock
혹은 사용자 설정을 먼저 하라고 나와있는데.. 일단 안해봤으니 보류
docker images로 잘 설치되어있는지, 현재 로컬에 존재하는 docker 이미지들을 확인
$ docker images
다음 명령을 통해 다운받은 jenkins 이미지를 container로 띄워 실행할 수 있다
$ sudo docker run -d -p 8080:8080 -v /jenkins:/var/jenkins_home --name jenkins -u root jenkins/jenkins:lts
이미 해당 이름 /jenkins 이미지가 실행중이다라는 에러가 나는 경우..
$ docker rm /jenkins로 지울 수 있다
https://stackoverflow.com/questions/31697828/docker-name-is-already-in-use-by-container
Docker - Name is already in use by container
Running the docker registry with below command always throws an error: dev:tmp me$ docker run \ -d --name registry-v1 \ -e SETTINGS_FLAVOR=local \ -e STORAGE_PATH=/registry \ -e
stackoverflow.com
옵션 자세한건 집에서 써보자..
4. jenkins 시작하기
EC2서버의 도메인주소:포트번호로 접속하면 이제는 익숙한 jenkins 시작화면이 보인다

당연히 내 컴퓨터가 아니고 도커 서버에서 실행중이라 파일을 도커에서 읽어야한다
docker exec 명령어는 컨테이너에 접속하는 명령어
# docker의 jenkins 컨테이너에 접속해서 /var/jenkins_home/secrets/initialAdminPassword 읽는다
$ docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
사용하면 다음과 같이 파일의 비밀번호를 읽는다

입력해서 넘어가자
그리고 install suggested plugins로 설치

설치가 끝나면 admin 계정을 생성하라는 아이디, 비밀번호, 이름, 이메일주소 입력하라고 나오는데
적당히 생성해주고 URL을 설정하라고 나온다.
그대로 next하고 start using jenkins 눌러서 시작

참조
https://gre-eny.tistory.com/345
[AWS] EC2의 Docker 위에 Jenkins Container 올리기
AWS EC2 Instance (Amazon Linux2) 에서 Docker로 Jenkins 이미지를 다운받아서 Container로 띄우는 것이 목표이다. ec2 인스턴스가 있다고 가정하고, Java나 Docker나 모두 설치되어 있다고 가정을 하고 시작한다. EC
gre-eny.tistory.com
'프로그래밍 > docker & jenkins' 카테고리의 다른 글
gitlab 프로젝트 CI/CD 환경 구축하기 6편 -gitlab에 push하면 자동으로 프론트엔드 빌드하기- (0) | 2023.02.04 |
---|---|
gitlab 프로젝트 CI/CD환경 구축하기 5편 -EC2 서버 내에서 프론트엔드 빌드하기- (0) | 2023.02.04 |
gitlab 프로젝트 CI/CD환경 구축하기 3편 -window에서 node.js & react 프로젝트 빌드해보기- (0) | 2023.02.02 |
gitlab 프로젝트 CI/CD 환경 구축하기 2편 -window에서 jenkins와 gitlab 프로젝트 연동하기 연습- (0) | 2023.02.02 |
gitlab 프로젝트 CI/CD환경 구축하기 1편 -jenkins 설치- (0) | 2023.02.02 |