"Docker cli"의 두 판 사이의 차이
(→Dockerfile) |
(→volume) |
||
(같은 사용자의 중간 판 14개는 보이지 않습니다) | |||
1번째 줄: | 1번째 줄: | ||
+ | 출처: https://docs.docker.com/engine/reference/commandline/cli/ | ||
+ | |||
==설치== | ==설치== | ||
21번째 줄: | 23번째 줄: | ||
$ docker load < [파일명].tar | $ docker load < [파일명].tar | ||
− | ==docker run== | + | ==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) | ||
+ | |||
+ | ==== Network Settings ==== | ||
+ | 참고: https://docs.docker.com/engine/tutorials/networkingcontainers/<syntaxhighlight> | ||
+ | --dns=[] : Set custom dns servers for the container | ||
+ | --network="bridge" : Connect a container to a network | ||
+ | 'bridge': create a network stack on the default Docker bridge | ||
+ | 'none': no networking | ||
+ | 'container:<name|id>': reuse another container's network stack | ||
+ | 'host': use the Docker host network stack | ||
+ | '<network-name>|<network-id>': connect to a user-defined network | ||
+ | --network-alias=[] : Add network-scoped alias for the container | ||
+ | --add-host="" : Add a line to /etc/hosts (host:IP) | ||
+ | --mac-address="" : Sets the container's Ethernet device's MAC address | ||
+ | --ip="" : Sets the container's Ethernet device's IPv4 address | ||
+ | --ip6="" : Sets the container's Ethernet device's IPv6 address | ||
+ | --link-local-ip=[] : Sets one or more container's Ethernet device's link local IPv4/IPv6 addresses | ||
+ | </syntaxhighlight>Supported networks : | ||
+ | {| class="wikitable" | ||
+ | !Network | ||
+ | !Description | ||
+ | |- | ||
+ | |'''none''' | ||
+ | |No networking in the container. | ||
+ | |- | ||
+ | |'''bridge''' (default) | ||
+ | |Connect the container to the bridge via veth interfaces. | ||
+ | |- | ||
+ | |'''host''' | ||
+ | |Use the host's network stack inside the container. | ||
+ | |- | ||
+ | |'''container'''<nowiki>:<name|id></nowiki> | ||
+ | |Use the network stack of another container, specified via its ''name'' or ''id''. | ||
+ | |- | ||
+ | |'''NETWORK''' | ||
+ | |Connects the container to a user created network (using <code>docker network create</code> command) | ||
+ | |} | ||
+ | 주의: <code>--network="host"</code> gives the container full access to local system services such as D-bus and is therefore considered insecure. | ||
− | === | + | === 예시 === |
$ docker run -it -e LC_ALL=C.UTF-8 ubuntu bash | $ 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== | ||
39번째 줄: | 89번째 줄: | ||
==build== | ==build== | ||
− | docker build [OPTIONS] PATH | URL | - | + | The <code>docker build</code> command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified <code>PATH</code> or <code>URL</code>. |
− | + | $ docker build [OPTIONS] PATH | URL | - | |
[[Dockerfile]] | [[Dockerfile]] | ||
+ | |||
+ | -t, --tag list Name and optionally a tag in the 'name:tag' format | ||
+ | |||
+ | -f Specify a Dockerfile | ||
== builder == | == builder == | ||
Manage builds. | Manage builds. | ||
+ | === prune === | ||
Remove build cache | Remove build cache | ||
$ docker builder prune | $ docker builder prune | ||
+ | |||
+ | == buildx == | ||
+ | Extended build capabilities with BuildKit | ||
+ | |||
+ | === ls === | ||
+ | List builder instances | ||
+ | $ docker buildx ls | ||
+ | |||
+ | === create === | ||
+ | Create a new builder instance | ||
+ | $ docker buildx create [OPTIONS] [CONTEXT|ENDPOINT] | ||
+ | options | ||
+ | |||
+ | --use Set the current builder instance | ||
+ | |||
+ | === inspect === | ||
+ | Inspect current builder instance | ||
+ | $ docker buildx inspect [NAME] | ||
+ | options | ||
+ | |||
+ | --bootstrap Ensure builder has booted before inspecting | ||
+ | |||
+ | === rm === | ||
+ | Remove a builder instance | ||
+ | $ docker buildx rm [NAME] | ||
== checkpoint == | == checkpoint == | ||
60번째 줄: | 140번째 줄: | ||
== volume == | == volume == | ||
+ | 도커에서 볼륨을 매핑하는 방법은 여러 가지가 있습니다. 그 중 하나는 호스트와 볼륨을 공유하는 것입니다. 도커가 관리하는 볼륨도 있다.(managed volumes) | ||
+ | |||
+ | 도커는 하나의 이미지로부터 여러 컨테이너를 만들기 위해서 '''Union File system'''을 사용한다. 유니온 파일 시스템은 원본 이미지에 변경된 내용(diff)를 추가하는 방식이므로, 다른 컨테이너에서 사용 할 수 없다. 애플리케이션에 따라서는 데이터를 다른 컨테이너와 공유 하거나 혹은 호스트에서 접근 할 수 있어야 하는 경우가 있는데, 이때 데이터 볼륨을 사용한다. (출처: https://www.joinc.co.kr/w/man/12/docker/Guide/DataWithContainer) | ||
=== prune === | === prune === | ||
71번째 줄: | 154번째 줄: | ||
== system == | == system == | ||
+ | Usage: docker system COMMAND | ||
+ | |||
+ | Manage Docker | ||
+ | |||
+ | Commands: | ||
+ | |||
+ | df Show docker disk usage | ||
+ | |||
+ | events Get real time events from the server | ||
+ | |||
+ | info Display system-wide information | ||
+ | |||
+ | prune Remove unused data | ||
+ | |||
+ | === prune === | ||
도커를 사용하다보면 더이상 사용하지 않는 컨테이너와 이미지들이 저장공간을 필요없이 차지하게 된다. 이런 데이터들을 한 번에 정리할 수 있는 명령어. | 도커를 사용하다보면 더이상 사용하지 않는 컨테이너와 이미지들이 저장공간을 필요없이 차지하게 된다. 이런 데이터들을 한 번에 정리할 수 있는 명령어. | ||
$ docker system prune --all --force | $ docker system prune --all --force | ||
+ | |||
+ | === df === | ||
+ | 볼륨 크기를 볼 수 있어 디스크 정리할 때 사용할 수 있다. | ||
+ | |||
+ | Show docker disk usage | ||
+ | |||
+ | Options: | ||
+ | |||
+ | --format string Pretty-print images using a Go template | ||
+ | |||
+ | -v, --verbose Show detailed information on space usage | ||
== config == | == config == | ||
101번째 줄: | 210번째 줄: | ||
=== Get an instance’s IP address === | === Get an instance’s IP address === | ||
$ docker inspect --format='<nowiki>{{range .NetworkSettings.Networks}}</nowiki><nowiki>{{.IPAddress}}</nowiki><nowiki>{{end}}</nowiki>' $INSTANCE_ID | $ docker inspect --format='<nowiki>{{range .NetworkSettings.Networks}}</nowiki><nowiki>{{.IPAddress}}</nowiki><nowiki>{{end}}</nowiki>' $INSTANCE_ID | ||
− | |||
− | |||
− | |||
== 외부링크 == | == 외부링크 == |
2023년 5월 26일 (금) 08:45 기준 최신판
설치편집
스크립트를 통한 설치편집
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)
Network Settings편집
참고: https://docs.docker.com/engine/tutorials/networkingcontainers/
--dns=[] : Set custom dns servers for the container
--network="bridge" : Connect a container to a network
'bridge': create a network stack on the default Docker bridge
'none': no networking
'container:<name|id>': reuse another container's network stack
'host': use the Docker host network stack
'<network-name>|<network-id>': connect to a user-defined network
--network-alias=[] : Add network-scoped alias for the container
--add-host="" : Add a line to /etc/hosts (host:IP)
--mac-address="" : Sets the container's Ethernet device's MAC address
--ip="" : Sets the container's Ethernet device's IPv4 address
--ip6="" : Sets the container's Ethernet device's IPv6 address
--link-local-ip=[] : Sets one or more container's Ethernet device's link local IPv4/IPv6 addresses
Supported networks :
Network | Description |
---|---|
none | No networking in the container. |
bridge (default) | Connect the container to the bridge via veth interfaces. |
host | Use the host's network stack inside the container. |
container:<name|id> | Use the network stack of another container, specified via its name or id. |
NETWORK | Connects the container to a user created network (using docker network create command)
|
주의: --network="host"
gives the container full access to local system services such as D-bus and is therefore considered insecure.
예시편집
$ 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편집
build편집
The docker build
command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH
or URL
.
$ docker build [OPTIONS] PATH | URL | -
-t, --tag list Name and optionally a tag in the 'name:tag' format
-f Specify a Dockerfile
builder편집
buildx편집
Extended build capabilities with BuildKit
ls편집
List builder instances
$ docker buildx ls
create편집
Create a new builder instance
$ docker buildx create [OPTIONS] [CONTEXT|ENDPOINT]
options
--use Set the current builder instance
inspect편집
Inspect current builder instance
$ docker buildx inspect [NAME]
options
--bootstrap Ensure builder has booted before inspecting
rm편집
Remove a builder instance
$ docker buildx rm [NAME]
checkpoint편집
$ docker checkpoint create
$ docker checkpoint ls [컨테이너]
$ docker checkpoint rm
cp편집
$ docker cp [container name]:[container 내부 경로] [host 파일경로]
volume편집
도커에서 볼륨을 매핑하는 방법은 여러 가지가 있습니다. 그 중 하나는 호스트와 볼륨을 공유하는 것입니다. 도커가 관리하는 볼륨도 있다.(managed volumes)
도커는 하나의 이미지로부터 여러 컨테이너를 만들기 위해서 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편집
Usage: docker system COMMAND
Manage Docker
Commands:
df Show docker disk usage
events Get real time events from the server
info Display system-wide information
prune Remove unused data
prune편집
도커를 사용하다보면 더이상 사용하지 않는 컨테이너와 이미지들이 저장공간을 필요없이 차지하게 된다. 이런 데이터들을 한 번에 정리할 수 있는 명령어.
$ docker system prune --all --force
df편집
볼륨 크기를 볼 수 있어 디스크 정리할 때 사용할 수 있다.
Show docker disk usage
Options:
--format string Pretty-print images using a Go template
-v, --verbose Show detailed information on space usage
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