Docker Cheatsheet


Docker 빠르게 다시 학습하기   도커 사용 방법에 관한 내용을 요약적으로 다룬다.

1. Orientation and setup

Enable Kubernetes

  • OSX

    • Enable "Kubernetes" - Docker icon in the menubar - preferences - kubernetes - Enable Kubernetes - apply

    • apiVersion: v1
      kind: Pod
        name: demo
        - name: testpod
          image: alpine:3.5
          command: ["ping", ""]
      kubectl apply -f pod.yaml  # pod/demo created
      kubectl get pods 
      # demo   1/1     Running   0          15s
      kubectl logs demo
      # PING ( 56 data bytes
      kubectl delete -f pod.yaml

Enable Docker Swarm

docker swarm init
# Swarm initialized: current node (n4uupxohx6wp0d4uhlw1o3ufc) is now a manager ~~ 같은 오류 메시지가 나옴

docker service create --name demo alpine:3.5 ping
# 00hrmr1i0ar92dcnn8zo55ta7
# overall progress: 1 out of 1 tasks
# 1/1: running
# verify: Service converged

docker service ps demo
# ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
# 1xfa8634l0w5        demo.1              alpine:3.5          docker-desktop      Running             Running 32 seconds ago

docker service logs demo
# demo.1.1xfa8634l0w5@docker-desktop    | PING ( 56 data bytes

docker service rm demo
# demo

docker servbice ls
# ID                  NAME                MODE                REPLICAS            IMAGE               PORTS

2. Containerizing an application

  • There is a project.
git clone -b v1
cd node-bulletin-board/bulletin-board-app
  • Dockerfile looks like this.
# Dockerfile inside bulletin-board-app
FROM node:6.11.5  # pre-existing node:6.11.5 image : official image

WORKDIR /usr/src/app
# Use WORKDIR to specify that all subsequent actions should be taken from the directory /usr/src/app in your image filesystem (never the host’s filesystem).

COPY package.json .
# COPY the file package.json from your host to the present location (.) in your image (so in this case, to /usr/src/app/package.json)

RUN npm install
# RUN the command npm install inside your image filesystem (which will read package.json to determine your app’s node dependencies, and install them)

COPY . .
# copy the rest of app's source code in bulletin-board-app to /usr/src/app

CMD [ "npm", "start" ]
  • how to build?
docker image build -t bulletinboard:1.0 .

# run
docker container run --publish 8000:8080 --detach --name bb bulletinboard:1.0
# fowardPort:presentPort

# terminate
docker container rm --force bb