주 메뉴 열기

wwiki β

Docker cli

Jhkim (토론 | 기여)님의 2022년 4월 10일 (일) 05:09 판 (volume)

설치

스크립트를 통한 설치

https://docs.docker.com/install/linux/docker-ce/#install-using-the-convenience-script

$ sudo wget -qO- https://get.docker.com/ | sh

arch계열에서 package manager를 통한 설치

$ sudo pacman -S docker

사용자 권한 추가

$ sudo usermod -aG docker $USER

다시 접속한 후에 적용된다.

commit

$ docker commit CONTAINER IMAGE_NAME

save

$ sudo docker save -o [파일명].tar 이미지명

load

$ docker load < [파일명].tar

run

$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Options

-v, --volume list Bind mount a volume

--volume-driver string Optional volume driver for the container

--volumes-from list Mount volumes from the specified container(s)

예시

$ docker run -it -e LC_ALL=C.UTF-8 ubuntu bash

한글입력을 위해서 로케일을 변경할 수 있다.

$ docker run -it --entrypoint bash ubuntu

--entrypoint string              Overwrite the default ENTRYPOINT of the image

attach

Attach local standard input, output, and error streams to a running container

$ sudo docker attach [컨테이너명]

종료시에는 ctrl+p, ctrl+q로 나가야 컨테이너가 종료되지 않는다.

exec

컨테이너 명령실행

$ sudo docker exec [컨테이너명] [명령어]

옵션

--user [사용자명]

build

docker build [OPTIONS] PATH | URL | -

$  docker build [OPTIONS] PATH | URL | -

Dockerfile

-t, --tag list Name and optionally a tag in the 'name:tag' format

-f Specify a Dockerfile

builder

Manage builds.

Remove build cache

$ docker builder prune

checkpoint

$ docker checkpoint create
$ docker checkpoint ls [컨테이너]
$ docker checkpoint rm

cp

$ docker cp [container name]:[container 내부 경로] [host 파일경로]

volume

도커는 하나의 이미지로부터 여러 컨테이너를 만들기 위해서 Union File system을 사용한다. 유니온 파일 시스템은 원본 이미지에 변경된 내용(diff)를 추가하는 방식이므로, 다른 컨테이너에서 사용 할 수 없다. 애플리케이션에 따라서는 데이터를 다른 컨테이너와 공유 하거나 혹은 호스트에서 접근 할 수 있어야 하는 경우가 있는데, 이때 데이터 볼륨을 사용한다.

출처: https://www.joinc.co.kr/w/man/12/docker/Guide/DataWithContainer

prune

Remove all unused local volumes

$ docker volume prune

network

ls

$ docker network ls [OPTIONS]

system

도커를 사용하다보면 더이상 사용하지 않는 컨테이너와 이미지들이 저장공간을 필요없이 차지하게 된다. 이런 데이터들을 한 번에 정리할 수 있는 명령어.

$ docker system prune --all --force

config

Create a config from a file or STDIN

$ docker config create [config] [file]
$ docker config inspect [config]

update

Update configuration of one or more containers

--cpus : Number of CPUs

$ docker update --cpus 2 container_name

https://docs.docker.com/engine/reference/commandline/update/#options

stats

Display a live stream of container(s) resource usage statistics

$ docker stats

info

Display system-wide information

$ docker info

inspect

Return low-level information on Docker objects

$ docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Get an instance’s IP address

$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID

외부링크

Node.js 웹 앱의 도커라이징

https://nodejs.org/ko/docs/guides/nodejs-docker-webapp/