반응형

 먼저 Dockerfile 이 있다고 가정한다. 

내가 만든 이미지는 spring boot 어플리케이션이다.


Dockerfile


1
2
3
4
5
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY ./build/libs/mail-0.0.1-SNAPSHOT.jar app.jar
RUN echo 'Mail Service running'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
cs


이제 이 Dockerfile 을 빌드를 한다.


sudo docker build -t asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1 .


docker build : 컨테이너를 만드는 명령어

-t : 이미지에 태그 정하는 옵션

asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1 : 후에 구글 컨테이너 레지스트리에 올리기 위한 이름 규칙이다.


[HOST_NAME]/[GOOGE_PROJECT_ID]/[IMAGE_NAME]


# 참고 (출처 : https://cloud.google.com/container-registry/docs/pushing-and-pulling)

  • gcr.io hosts the images in the United States, but the location may change in the future
  • us.gcr.io hosts the image in the United States, in a separate storage bucket from images hosted by gcr.io
  • eu.gcr.io hosts the images in the European Union
  • asia.gcr.io hosts the images in Asia


1
2
3
4
5
sudo docker images
REPOSITORY                                        TAG                 IMAGE ID            CREATED             SIZE
asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service    v1                  2f19bede54dd        19 minutes ago      140MB
openjdk                                           8-jdk-alpine        54ae553cb104        5 weeks ago         103MB
hello-world                                       latest              4ab4c602aa5e        5 weeks ago         1.84kB
cs


이미지가 생성되면 위와 같이 볼수 있다. PROJECT_ID 는 일부러 [GOOGLE_PROJECT_ID] 라고 변경했다.

이제 이미지를 PUSH 해보자


1
2
3
4
5
6
7
8
sudo docker push asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1
The push refers to repository [asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service]
fcb96fbc948c: Preparing 
f2ec1bba02a6: Preparing 
0c3170905795: Preparing 
df64d3292fd6: Preparing 
unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.
com/container-registry/docs/advanced-authentication
cs


안된다...

뭔가 인증작업이 필요하다.

저기 표시된 url  로 일단 들어가보자. https://cloud.google.com/container-registry/docs/advanced-authentication


거기 가이드 대로 따라해보면 다음과 같은 과정을 거치게 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
gcloud auth configure-docker
WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
The following settings will be added to your Docker config file 
located at [/home/gcpblusky0910/.docker/config.json]:
 {
  "credHelpers": {
    "gcr.io": "gcloud", 
    "us.gcr.io": "gcloud", 
    "eu.gcr.io": "gcloud", 
    "asia.gcr.io": "gcloud", 
    "staging-k8s.gcr.io": "gcloud", 
    "marketplace.gcr.io": "gcloud"
  }
}
 
Do you want to continue (Y/n)?  y
 
Docker configuration file updated.
cs


그런데 위에 내용이 뭔가 좀 이상하다. 

config 파일에 내용이 들어가긴 했는데 다음과 같은 문구가 눈에 거슬린다.


WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.


'docker-credential-gcloud' 가 PATH에 없어서 Docker credential helper 를 설정했지만 정상적으로 동작 안할꺼다.. 라는 내용이다. 뭐지???


1
gcloud components install docker-credential-gcr
cs


이렇게 했더니 다시 에러가 난다. 이번에는 Cloud SDK 가 뭔가 없다고 한다. 


그래서 아래 URL 로 이동해서 Cloud SDK 를 설치했다.


https://cloud.google.com/sdk/docs/downloads-apt-get


거기에 있는 명령어들을 쭉 실행 한다음 마지막에 gcloud init 까지 한다.


1
2
gcloud auth configure-docker
gcloud credential helpers already registered correctly.
cs
gcloud components install docker-credential-gcr


이제서야 Error 없이 뭔가 OK 라고 나온다.


이제 다시 이미지는 컨테이너 레지스트리에 push를 해보자.


1
2
3
4
5
6
7
sudo docker push asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1
The push refers to repository [asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service]
fcb96fbc948c: Pushed 
f2ec1bba02a6: Layer already exists 
0c3170905795: Layer already exists 
df64d3292fd6: Layer already exists 
v1: digest: sha256:465521bc0b83e3a3177c25f1f120f96bef3d585046f0b4cb4ede4d42d1fafc7a size: 1159
cs



이렇게 내 계정의 Container Registry 를 확인해보면 정상적으로 업로드가 됐다.


728x90
반응형

'Development > GoogleCloud' 카테고리의 다른 글

[GCP] Google Cloud Storage Options.  (0) 2019.12.12
[GCP]VPC Network  (0) 2019.08.03
[GCP] Network  (0) 2019.08.01
[GCP]HTTP(S) Load Balancing  (0) 2019.07.31
[GCP]Network TCP/UDP Load Balancing  (0) 2019.07.28

+ Recent posts