HOWTO

squid http proxy 사용해서 aws ecr 에 docker image push 하기

한크크 2021. 12. 29. 15:30

aws 의 ecr 에 private link 가 생겨서 접근 가능한 IP 를 제어할 수 있지만, 이전에는 http proxy 를 통해서 접근할 수 있는 IP 를 제어했다. ecr 에 사용할 일은 없겠지만, 인터넷 사용이 제한적이거나 source IP 를 proxy 로 제한하고 싶은 경우 squid proxy 를 사용할 수 있고, docker registry 로 push 하는 경우 https 를 사용하지만 별도의 docker 설정이 필요하므로 기록해둔다. 

 

1. proxy 서버에 squid proxy 설치 

위 그림에서는 ec2 에 설치, proxy 통신을 위한 acg, nacl 설정은 완료한 상태라고 가정한다. 

yum install squid -y

squid.conf 수정 후 재시작

vi /etc/squid/squid.conf

# >> http_access allow all 추가 <<
# And finally deny all other access to this proxy
#http_access deny all -> 주석처리
http_access allow all

# Squid normally listens to port 3128
http_port 3128

systemctl restart squid

 

2. docker image push 할 서버 

위 그림에서는 docker client 서버, 마찬가지로 acg, nacl 설정은 완료한 상태라고 가정한다. 

# proxy.sh 파일 생성 후 proxy 서버 정보 추가 
vi /etc/profile.d/proxy.sh

export http_proxy=http://34.xxx.xxx.xxx:3128
export https_proxy=https://34.xxx.xxx.xxx:3128

위 설정 후 ssh 로그인을 다시 해야 반영된다. 

vi /etc/systemd/system/docker.service.d/http_proxy.conf

[Service]
Environment="HTTP_PROXY=http://34.xxx.xxx.xxx:3128"
Environment="NO_PROXY=localhost,127.0.0.1"

docker registry 에서 http 를 사용하지만 http_proxy 설정만 해두면 docker push 할 때 squid Proxy 를 타고 나가지 않는다. 

docker 환경 설정을 해줘야지만 squid proxy 를 통해 트래픽이 나간다. https 를 사용하지만 environment 에 squid 와 같이 https 도 설정해주면 에러난다. http 만 설정해야 된다. 

 

3. docker push 실행 및 squid proxy log 확인

모든 준비는 끝났으므로 docker push 를 2번에서 설정한 서버에서 실행한다. 

docker push 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com/exxxxxv:largeimage
The push refers to repository [578xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com/exxxxxv]
85bc43fa95f1: Pushing [==========================>                        ]  2.712GB/5.12GB
85bc43fa95f1: Pushing [==========================>                        ]  2.716GB/5.12GB
85bc43fa95f1: Pushed

largeimage: digest: sha256:16c4cd5625077aa183c4082f8ba8d146bcfd8baf14e6dac80e00e39ff1635ca8 size: 742

proxy 서버의 /var/log/squid/access.log 를 확인했을 때 아래와 같이 docker push 명령이 squid 를 통과하는 로그가 찍혀야 한다. 

1640742486.957   1221 110.234.2.175 TCP_TUNNEL/200 6025 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742487.967    815 110.234.2.175 TCP_TUNNEL/200 5941 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742489.050    863 110.234.2.175 TCP_TUNNEL/200 5752 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742490.100    863 110.234.2.175 TCP_TUNNEL/200 5949 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742491.158    868 110.234.2.175 TCP_TUNNEL/200 5978 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742492.372   1003 110.234.2.175 TCP_TUNNEL/200 6025 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742493.410    843 110.234.2.175 TCP_TUNNEL/200 5929 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -
1640742494.563    948 110.234.2.175 TCP_TUNNEL/200 5875 CONNECT 57xxxxxxxx65.dkr.ecr.us-west-2.amazonaws.com:443 - HIER_DIRECT/52.35.2.78 -

 

반응형