Skip to content
jaeseok.an edited this page Oct 22, 2019 · 16 revisions

command

  • CMD
    • container시작시 수행 명령
    • docker file당 1개
    • 시작시 override 가능
  • ENTRYPOINT
    • container시작시
    • override불가 . 즉 변경없이 무조건 실행되어야 할 내용.
    • run image arg 로 argument받을수 있음
  • CMD vs ENTRYPOINT
    • runtime에 override될 default argument가 있다면 CMD 좋음
    • excutable을 실행하거나, 매번 변경없이 실행하고자 하면 ENTRYPOINT가 좋음
  • WORKDIR
    • cd와 같음
  • COPY/ADD
    • ADD는 tar를 풀어서 올림

유용한 cli command

  • Containers
    • Use docker container my_command
    create — Create a container from an image. 
    start — Start an existing container. 
    run — Create a new container and start it. 
    ls — List running containers. 
    inspect — See lots of info about a container.
    logs — Print logs. 
    stop — Gracefully stop running container. 
    kill —Stop main process in container abruptly. 
    rm— Delete a stopped container.
    
  • Images
    • Use docker image my_command
    build — Build an image.
    push — Push an image to a remote registry.
    ls — List images. 
    history — See intermediate image info.
    inspect — See lots of info about an image, including the layers. 
    rm — Delete an image.
    
  • Misc
    docker version — List info about your Docker Client and Server versions.
    docker login — Log in to a Docker registry.
    docker system prune — Delete all unused containers, unused networks, and dangling images.
    

tip

  • image size
    • docker image ls

multistage

  • 이전 stage의 결과만 재사용
    • COPY --from=
FROM golang:1.7.3 AS build
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html  
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=build /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]

image 사이즈 줄이기

  • 되도록 RUN에서 여러 command 실행. 각 run마다 layer가 생성되기 때문
RUN apt-get update && apt-get install -y \
    package-one \
    package-two 
 && rm -rf /var/lib/apt/lists/*

copy 파일

docker cp foo.txt mycontainer:/foo.txt
docker cp mycontainer:/foo.txt . 

test

Clone this wiki locally