docker 는 https 로 동작하므로 nexus 를 https 로 설정 필요(http://books.sonatype.com/nexus-book/3.1/reference/security.html#ssl-inbound)

Private 저장소

Docker 저장소 설정

Proxy Repository

  • Define Name
  • Define URL for Remote storage - https://registry-1.docker.io
  • Enable Docker V1 API support, if required by the remote repository
  • Select correct Docker index, further configure Location of Docker index if needed
  • Select Blob store for Storage

 

Hosted Repository(private)

  • Define Name
  • Select Blob store for Storage


Repogistory Group

  • Define Name
  • Select Blob store for Storage
  • Add Docker repositories to the Members list in the desired order

 

  • docker 가 direct 로 연결할 수 있는 HTTP Connector 를 만들어 줘야하며 docker 는 HTTPS 만 사용
  • nexus 에 사용할 포트를 expose reverse proxy https 를 사용하므로 HTTP로 해줘도 됨.

 

API v1 사용을 꼭 체크할 것!!

 

nginx

server {
    listen       18443;
	server_name  nexus.example.com;
 
	location / {
        proxy_pass   http://127.0.0.1:5444;
        proxy_set_header        Host                    $host;
        proxy_set_header        X-Real-IP               $remote_addr;
        proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto       "https";
	}
}
CODE

proxy_pass 에 위에서 노출한 HTTP Connector 포트 매핑

login

docker login nexus.example.com:18443
CODE

Windows 일 경우 localhost 에 direct 로 연결하면 connection refused 에러 발생하므로 IP 를 주어야 함.

아래 대신

docker login localhost:8444
CODE

 

이렇게

docker login my-pc-ip:8444
CODE

Docker 사용

--insecure-registry 설정

도커는 기본적으로 TLS(https)를 사용하므로 사설 저장소에 https를 설정하거나 아니면 --insecure-registry 설정을 해주고 docker daemon 제구동해야 함

DOCKER_OPTS="--insecure-registry :8004"
CODE

cmd 

docker <command> <nexus-hostname>:<repository-port>/<namespace>/<image>:<tag>
CODE
docker search <nexus-hostname>:<repository-port>/<search-term>
CODE
postgres 를 검색할 때
docker search nexus.lesstif.com:18443/postgres
CODE

 

pull

다음과 같이 image:tag형식으로 가져옴

docker pull nexus.lesstif.com:18443/ubuntu
CODE
docker pull nexus.lesstif.com:18443/postgres:9.4
CODE


push images

태그후 푸시 필요

docker tag <imageId or imageName> <nexus-hostname>:<repository-port>/<image>:<tag>
CODE

올리기

docker tag af340544ed62 nexus.example.com:18443/hello-world:mytag
CODE
docker push nexus.lesstif.com:18443/hello-world:labeltest
CODE

실전 예제

  1. ubuntu 검색

    $ docker search nexus.lesstif.com:18443/ubuntu
    CODE
  2. pull ubuntu 14

    $ docker pull nexus.lesstif.com:18443/ubuntu:14.04 
    CODE
  3. image 확인

    $ docker image 
    CODE

  4. run

    $ docker run -it nexus.lesstif.com:18443/ubuntu:14.04
    CODE

    한 번 실행해주면 그 다음에는 ubuntu 라는 이미지 이름만으로 실행 가능.(기존 ubuntu 라는 이미지 이름이 없어야 함)

  5. container 에 lsof 설치

    # lsof
     command not found
    # apt update
    # apt install lsof
    # lsof -i TCP:80
    CODE
  6. container 에서 나옴

    exit
    CODE
  7. 컨테이너 id 조회

    $ docker ps -a
    CODE
  8. docker commit으로 컨터이너 변경 저장

    $ docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
    CODE

    포트에 주의.

    $ docker commit -m "install lsof" -a "lesstif" 11ef110062a5 nexus.lesstif.com:18444/ubuntu:basic    
    CODE
  9. push

    group 이나 proxy repository 에는 푸시 할수 없으므로 커넥터 추가 필요!!

    $ docker push nexus.lesstif.com:18444/ubuntu:basic
    CODE
  10. nexus 관리자에 로그인하면 아래와 같이 이미지가 등록된 것을 확인할 수 있음
     
  11. 2

 

Ref