2020년 3월 27일 금요일

Push Docker Image to GCR from WSL

[업데이트 2026-10]

Container Registry(gcr.io)는 종료되어 2025년 3월 18일부터 이미지 쓰기가 막혔다. 아래 gcr.io 푸시 방식은 그대로는 쓸 수 없고, Artifact Registry를 쓰거나 gcr.io 주소를 Artifact Registry로 마이그레이션해야 한다. 서울 리전 기준으로는 이렇게 한다.

$ gcloud auth configure-docker asia-northeast3-docker.pkg.dev
$ gcloud artifacts repositories create REPO --repository-format=docker --location=asia-northeast3
$ docker tag config-server asia-northeast3-docker.pkg.dev/PROJECT_ID/REPO/config-server:latest
$ docker push asia-northeast3-docker.pkg.dev/PROJECT_ID/REPO/config-server:latest

이메일, 프로젝트 ID, 로그인 URL, PC 이름은 노출을 피하려고 가렸다. 아래는 2020년 당시 기록이다.


user@pc:~$ docker images
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
asia.gcr.io/PROJECT_ID/config-server   latest              f9559cb4a95e        25 hours ago        135MB
test/configserver                                latest              f9559cb4a95e        25 hours ago        135MB
openjdk                                          8-jdk-alpine        a3562aa0b991        10 months ago       105MB
hello-world                                      latest              fce289e99eb9        15 months ago       1.84kB

user@pc:~$ docker push asia.gcr.io/PROJECT_ID/config-server
WARNING: Could not open the configuration file: [/home/user/.config/gcloud/configurations/config_default].
ERROR: (gcloud.auth.docker-helper) You do not currently have an active account selected.
Please run:

  $ gcloud auth login

to obtain new credentials, or if you have already logged in with a
different account:

  $ gcloud config set account ACCOUNT

to select an already authenticated account to use.
The push refers to repository [asia.gcr.io/PROJECT_ID/config-server]
9bb9d4296990: Preparing
ceaf9e1ebef5: Preparing
9b9b7f3d56a0: Preparing
f1b5933fe4b5: 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
user@pc:~$ gcloud auth login
Go to the following link in your browser:

    (로그인 URL 생략)


Enter verification code: <Hidden>

You are now logged in as [계정 이메일].
Your current project is [None].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID

user@pc:~$ gcloud config set project PROJECT_ID
Updated property [core/project].


user@pc:~$ docker push asia.gcr.io/PROJECT_ID/config-server
The push refers to repository [asia.gcr.io/PROJECT_ID/config-server]
9bb9d4296990: Pushed
ceaf9e1ebef5: Layer already exists
9b9b7f3d56a0: Layer already exists
f1b5933fe4b5: Layer already exists
latest: digest: sha256:5b309a37ba393e74461b10eb52c96b4dc670425b1ba546ffa27f618e607ef6d5 size: 1159




2020년 3월 22일 일요일

Install gcloud on WSL (Ubuntu)

1) Run WSL

2) Add the Cloud SDK distribution URI as a package source
$ echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
3) Install apt-transport-https
$ sudo apt-get install apt-transport-https ca-certificates gnupg

4) Import the Google Cloud Platform public key
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg

5) Update the package list and install the Cloud SDK
$ sudo apt-get update && sudo apt-get install google-cloud-cli

6) Install Additional Component
$ sudo apt-get install google-cloud-cli-app-engine-java

7) Start gcloud
$ gcloud init

[업데이트 2026-10]

  • apt-key 방식은 더 이상 권장되지 않아서 공개키 등록을 gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg로, 저장소 주소를 https로 바꿨다.
  • 패키지 이름이 google-cloud-sdk에서 google-cloud-cli로 바뀌어서 5번과 6번 명령도 고쳤다. (App Engine Java 컴포넌트는 google-cloud-cli-app-engine-java)
  • 공식 문서 기준으로는 3번에서 apt-transport-https 없이 ca-certificates gnupg curl만 설치한다.
  • WSL 자체를 새로 설치한다면 wsl --install 한 줄로 끝난다.

2020년 3월 20일 금요일

docker-compose error (Unable to enable NAT rule)

$ docker-compose up -d
Creating network "chapter04_default" with the default driver
ERROR: Failed to Setup IP tables: Unable to enable NAT rule:  (iptables failed: iptables --wait -t nat -I POSTROUTING -s 172.21.0.0/16 ! -o br-8cbf06e4b2c9 -j MASQUERADE: iptables: No chain/target/match by that name.
 (exit status 1))

[Fix]
$ sudo vi /etc/docker/daemon.json
{
    "iptables":false
}

and then..

restart dockerd


[업데이트 2026-10]

  • "iptables": false는 도커가 iptables 규칙(NAT, 포트 공개)을 자동으로 만들지 않게 하는 임시 우회 방법이다. 이 상태에서는 컨테이너의 외부 통신이나 -p 포트 공개가 안 될 수 있다.
  • 이 오류는 WSL1처럼 iptables 관련 커널 모듈이 없는 환경에서 날 수 있다. 가능하면 WSL2를 쓰는 편이 낫고, 우회가 필요 없어졌다면 daemon.json 설정은 되돌려 둔다.

2020년 3월 18일 수요일

docker daemon is not running in WSL Ubuntu

1. Launch WSL with admin priviledge
2. su - root
3. dockerd

[업데이트 2026-10]

  • WSL에서는 sudo service docker start로 도커 데몬을 띄우는 방법도 있다. root로 dockerd를 직접 실행하면 그 터미널을 닫을 때 같이 종료된다.
  • WSL2에서 systemd를 켜 두었다면 부팅할 때 도커가 자동으로 올라오게 설정할 수 있다. 번거로우면 Windows용 Docker Desktop을 쓰는 방법도 있다.

2020년 3월 17일 화요일

Setting or change WSL root password

1. Open PowerShell Console
2. Comand
PS C:\Users\user> wsl -u root
root@pc:/mnt/c/Users/user#
root@pc:/mnt/c/Users/user# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


[업데이트 2026-10]

  • 배포판을 지정해야 하면 wsl -d Ubuntu -u root처럼 쓴다. 설치된 배포판 이름은 wsl -l -v로 확인한다.
  • 일반 사용자의 비밀번호를 바꿀 때는 root로 들어가서 passwd 사용자명을 실행한다.
  • PC 이름과 Windows 계정명은 가려 두었다.

2020년 3월 16일 월요일

Google Cloud SDK 설치


download & install : https://cloud.google.com/sdk/docs/quickstart-windows
Set Seoul Region / Zone : asia-northeast3-a

[업데이트 2026-10]

  • 위의 quickstart 주소는 예전 문서다. 지금은 공식 설치 문서(https://cloud.google.com/sdk/docs/install)에서 Windows 설치 파일을 받는다.
  • 설치 후 gcloud init으로 로그인과 프로젝트를 고르고, 서울 리전/존은 아래처럼 지정한다.
gcloud config set compute/region asia-northeast3
gcloud config set compute/zone asia-northeast3-a

install jdk8 on Ubuntu

$ sudo apt install openjdk-8-jdk
$ java -version

[업데이트 2026-10]

  • JDK 8은 오래된 프로젝트를 돌릴 때만 필요하다. 새로 시작한다면 LTS 버전을 설치한다. sudo apt install openjdk-17-jdk 또는 openjdk-21-jdk (배포판에 없는 버전이면 apt search openjdk로 확인)
  • 여러 버전을 같이 설치했다면 sudo update-alternatives --config java로 기본 버전을 고른다.

Install for Ubuntu 18.04 LTS on Windows10 ( WLS )

[업데이트 2026-10]

  • 지금은 관리자 PowerShell에서 wsl --install 한 줄이면 WSL 기능 활성화와 Ubuntu 설치까지 된다. Windows 10 2004(빌드 19041) 이상 또는 Windows 11에서 쓸 수 있고, 새로 설치하면 기본이 WSL 2다.
  • 다른 배포판은 wsl --list --online으로 목록을 보고 wsl --install -d 배포판이름으로 설치한다.
  • Ubuntu 18.04는 오래된 버전이라 새로 설치한다면 더 최신 LTS를 쓴다. 아래 순서는 2020년 당시 방식이다.

1. 관리자 권한으로 PowerShell 실행
2. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 실행
3. https://www.microsoft.com/ko-kr/p/ubuntu-1804-lts/9n9tngvndl3q?rtc=1&activetab=pivot:overviewtab
4. Download & Install
5. Launch & Create Account / Password

2020년 3월 15일 일요일

Install Springboot CLI on Ubuntu

0. PreRequisite
 $ sudo apt install unzip
 $ sudo apt install zip

1. Install SDKMAN

$ curl -s https://get.sdkman.io | bash
$ source ~/.bashrc

2. Install SpringBoot
$ sdk install springboot
$ spring version

$ spring init \
     --boot-version=2.1.0.RC1  \
     --build=gradle \
     --java-version=1.8 \
     --packaging=jar \
     --name=product-service  \
     --package-name=se.magnus.microservices.core.product \
     --groupId=se.magnus.microservices.core.product \
     --dependencies=actuator,webflux  \
     --version=1.0.0-SNAPSHOT \
     product-service

[업데이트 2026-10]

  • SDKMAN으로 설치하는 방법은 그대로 쓸 수 있다. sdk install springboot는 최신 CLI를 설치한다.
  • 예제의 --boot-version=2.1.0.RC1은 오래된 프리릴리스 버전이다. 새로 만든다면 이 옵션을 빼거나 start.spring.io에서 현재 버전을 확인해서 쓴다.
  • 최신 Spring Boot는 Java 17 이상이 필요해서 예제의 --java-version=1.8도 그에 맞춰 바꿔야 한다.

2020년 3월 14일 토요일

fix for VirtualBox Shared Folder fs type error

$ sudo mount -t vboxsf share /mnt/share
mount: /mnt/share: wrong fs type, bad option, bad superblock on share, missing codepage or helper program, or other error.

$ sudo apt-get install virtualbox-guest-utils

$ sudo mount -t vboxsf share /mnt/share

[업데이트 2026-10]

  • 마운트는 되는데 접근 권한 오류가 나면 사용자를 vboxsf 그룹에 넣고 다시 로그인한다. sudo usermod -aG vboxsf $USER
  • 또는 마운트할 때 소유자를 지정할 수 있다. sudo mount -t vboxsf -o uid=$(id -u),gid=$(id -g) share /mnt/share
  • 공유 폴더는 게스트 확장(Guest Additions)이 설치되어 있어야 동작한다. 패키지 이름은 배포판에 따라 다를 수 있다.