AWS EC2 환경이며 Ubuntu 22.04.1 LTS 버전 및 docker 20.10.18 버전에서 구성 진행을 했습니다.
Private 구축이 조건이였기 때문에 Private Subnet에 EC2 구성을 했고 Route53과 ALB 연결을 사전
진행을 완료한 상태입니다.
Nexus3를 EC2에 구성 시 발생할 수 있는 일부 상황은 아래 페이지에서 확인이 가능합니다.
Nexus 데이터가 들어갈 디렉터리 생성을 합니다.
$ mkdir nexus-data
$ ls
nexus-data
Shell
Nexus container 생성
$ docker run --name nexus -d -p 5000:5000 -p 8081:8081 -v /nexus-data:/nexus-data -u root sonatype/nexus3
Unable to find image 'sonatype/nexus3:latest' locally
latest: Pulling from sonatype/nexus3
a96e4e55e78a: Pull complete
67d8ef478732: Pull complete
5dab04a94e74: Pull complete
f18da266a531: Pull complete
8eaab91b309d: Pull complete
9191b3fc4348: Pull complete
16516688603a: Pull complete
Digest: sha256:45e9800b160a6ae666f64cead6a6118c151f2fc2973f55
Status: Downloaded newer image for sonatype/nexus3:latest
2238bbd6e0e44f1d85e704ad6433b8e73
Shell
기동이 완료된 후 생성한 도메인으로 접속하면 메인 페이지 확인이 가능합니다.
Sign in을 하기 위해서 버튼을 누르면 ID는 admin이지만 초기 패스워드는 도커로 구성한 내부에서 /nexus-data/admin.password 파일에서 확인이 가능합니다.
docker 내부로 접속하기 위해서 nexus docker 정보를 다시 확인하고 접속해서 패스워드를 확인합니다.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
351f64194d8f sonatype/nexus3 "/opt/sonatype/nexus…" 2 hours ago Up 2 hours 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp, 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp nexus
$ docker exec -it nexus /bin/bash
[root@351f64194d8f sonatype]# cd sonatype-work
[root@351f64194d8f sonatype]# cd nexus3
[root@351f64194d8f nexus3]# ls
admin.password blobs cache db elasticsearch etc generated-bundles instances javaprefs karaf.pid keystores lock log orient port restore-from-backup tmp
[root@351f64194d8f nexus3]# cat admin.password
나만의 패스워드 확인
Shell
로그인 이후 안내 페이지를 통해서 신규 패스워드 변경과 익명 접근에 대한 설정을 할 수 있습니다.
새로운 패스워드로 변경합니다.
docker repository를 생성하기 위해서 메인 페이지에서 톱니바퀴(관리 페이지)를 눌러스 변경합니다.
톱니바퀴 → Repository → Blob Stores → Create Blob Store
S3와 File Type을 지원하고 여기서는 File Type으로 진행합니다. 사용할 Name을 입력하고 Save 선택합니다.
정상적으로 생성된 것을 확인할 수 있습니다.
docker (hosted) 선택
•
Name : docker-hosted
•
HTTP 영역 체크 및 5000번 포트 입력
•
Enable Docker V1 API 체크
•
Blob store docker-hosted 선택
docker-hosted 생성이 완료됐습니다.
두번째 docker-hub 생성
•
Name : docker-hub
•
Enable Docker V1 API 체크
•
Remote storage 주소에 예제에 나와 있는 https://registry-1.docker.io 입력
•
Use Docker Hub 선택
Nexus에서 Realms 설정
톱니바퀴(관리 콘솔) → Security → Realms → Docker Bearer Token Realm 선택 후 Save 선택
docker 명령어 http 사용 가능 설정
EC2 환경에서 /etc/docker/daemon.json 파일 생성 후 아래 내용을 작성합니다.
{
"insecure-registries" : ["172.16.8.35:5000"]
}
Shell
적용을 위해서 docker 및 nexus 재기동합니다.
$ sudo service docker restart
$ docker start nexus
사내 Docker 저장소 로그인
$ docker login 172.16.8.35:5000
이때 패스워드 항목은 nexus 콘솔에서 login 하는 패스워드와 동일합니다.
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
Shell
만약 다른 서버(클라이언트)에서 nexus 서버로 login하기 위해서는 EC2 Security Group에서 5000번 포트 허용을 해야 접근이 가능하다.
허용이 안되어 있을 때는 아래와 같은 에러 메시지가 발생할 수 있다.
Error response from daemon: Get "http://172.16.8.35:5000/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Shell
로그인 이후에 테스트 목적으로 busybox 이미지 pull
$ docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
729ce43e2c91: Pull complete
Digest: sha256:ad9bd57a3a57cc95515c537b89aaa69d83a6df54c4050fcf2b41ad367bec0cd5
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
Shell
$ docker images -a
busybox latest 2bd29714875d 9 days ago 1.24MB
sonatype/nexus3 latest 11ff0b1c5ab7 4 weeks ago 550MB
Shell
$ docker tag 2bd29714875d 172.16.8.35:5000/busybox:v20220923
$ docker images
172.16.8.35:5000/busybox v20220923 2bd29714875d 9 days ago 1.24MB
busybox latest 2bd29714875d 9 days ago 1.24MB
sonatype/nexus3 latest 11ff0b1c5ab7 4 weeks ago 550MB
Shell
$ docker push 172.16.8.35:5000/busybox:v20220923
The push refers to repository [172.16.8.35:5000/busybox]
3e9498aeb76f: Pushed
v20220923: digest: sha256:bbb248c803ff97f51db3b37a2a604a6270cd2ee1ca9266120aeccb3b19ce80d2 size: 527
Shell
이제 nexus 콘솔에서 확인
Browse → docker-hosted