gcloud auth list -> active 계정 이름 확인
gcloud config list project -> 프로젝트 ID 확인
Docker 파일 실행해보기
hello-world라는 container 실행
docker run hello-world
코드 실행 과정
도커 daemon이 hello-world라는 image를 로컬에서 확인
image가 없다면 Docker Hub라는 public registry에서 다운로드하여 사용
현재 사용 가능한 도커 images 확인
사용 가능하려면 도커 이미지가 built 돼야 함
docker images
현재 실행 중인 container 확인 하기
docker ps
현재는 안 쓰고 기존에 사용했던 containers까지 확인하기
docker ps -a
->
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2eaebdcdd00 hello-world "/hello" 9 minutes ago Exited (0) 9 minutes ago amazing_heyrovsky
이때, docker run 실행 시 container의 이름은 임의로 할당
docker run --name container-name hello-world 사용하면 이름 할당 가능
Docker Image 구성하기
Dockerfile 만들기
FROM node:lts : base parent image로 lts(long term support) 선택
WORKDIR /app : container 작업 폴더 선택
ADD . /app : container의 컨텐츠 설정
EXPOSE 80 : 80 포트 개방
CMD ["node", "app.js"] : container가 실행 될 때 node를 통해 app.js 실행
cat > Dockerfile <<EOF
# Use an official Node runtime as the parent image
FROM node:lts
# Set the working directory in the container to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Make the container's port 80 available to the outside world
EXPOSE 80
# Run app.js using node when the container launches
CMD ["node", "app.js"]
EOF
project-id는 gcloud config list project 를 통해서 확인 가능
container publish 진행
docker tag node-app:0.2 gcr.io/project-id/node-app:0.2
docker images
gcr.io/[project-id]/node-app 가 추가 됨
REPOSITORY TAG IMAGE ID CREATED
node-app 0.2 76b3beef845e 22 hours ago
gcr.io/[project-id]/node-app 0.2 76b3beef845e 22 hours ago
node-app 0.1 f166cd2a9f10 26 hours ago
node lts 5a767079e3df 7 days ago
hello-world latest 1815c82652c0 7 weeks ago