반응형

 먼저 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
반응형

명령어 절차를 매번 찾기 귀찮아서 이렇게 기록 놓기로 했다.


1. 먼저 Github에 새로운 Repository 하나를 생성한다.



2. 실제 repository에 올리고 싶은 프로젝트의 로컬 디렉토리로 이동해서 git init 명령어를 실행한다. 그리고 git status 를 실행하면 아래와 같이 나온다.



3. git add . 명령어를 실행한다. 



4. git commit -m "커밋 메세지" 를 실행한다.



5. 1번에서 만들어 놓았던 repository 의 주소를 복사한다.


6. git remote add origin 복사한 주소 를 실행한다.


7. git push -u origin master 를 실행한다. 그런 다음 아무 에러가 안나면 끝난다. 

그런데 이때 reject 가 나오는 경우가 있다. Git Repository 를 생성할때 ReadeME  파일을 생성하도록 하면 이미 commit 한 내용이 있기 때문에 pull 을 받으라고 나온다.



 그런데 막상 pull을 받으면 아래와 같이 메세지가 나온다.



이때에는 git pull origin master 라고 입력해주면 된다. 


그리고 또 혹~~ 시라도 아래와 같은 메세지가 나오는 경우가 있다.


fatal: refusing to merge unrelated histories


이 에러는 각각의 history를 가진 프로젝트를 병합 하려고 할때 나온다고 한다. 그럴 경우에는 아래와 같이 옵션을 추가해서 pull을 받아야 한다.


git pull origin <branch name> --allow-unrelated-histories


참고 사이트

https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

https://hongjinseob.wordpress.com/2017/11/24/git-fatalrefusing-to-merge-unrelated-histories-%ED%95%B4%EA%B2%B0/

728x90
반응형

+ Recent posts