웹사이트 검색

공식 명령줄 클라이언트인 Doctl 사용 방법


이 튜토리얼의 이전 버전은 Brennen Bearnes가 작성했습니다.

소개

DigitalOcean의 웹 기반 제어판은 Droplet 관리를 위한 포인트 앤 클릭 인터페이스를 제공합니다. 그러나 관리할 Droplet이 많거나, 사용 가능한 그래픽 데스크톱 없이 터미널에서 Droplet을 관리해야 하거나, 스크립트 가능한 인터페이스에서 이점을 얻을 수 있는 작업이 있는 경우 명령줄 도구를 선호할 수 있습니다.

doctl은 공식 DigitalOcean 명령줄 클라이언트입니다. DigitalOcean API를 사용하여 대부분의 계정 및 Droplet 기능에 대한 액세스를 제공합니다.

전제 조건

이 자습서를 따르려면 다음이 필요합니다.

  • 프로젝트의 설치 및 구성 지침에 따라 doctl이 설치된 로컬 컴퓨터.

이 자습서는 대부분의 doctl 작업에 대한 참조용으로 작성되었습니다. doctl 명령은 API와 밀접하게 유사하므로 DigitalOcean API v2 사용 방법을 읽는 것도 도움이 될 수 있습니다.

일반 doctl 사용법

명령 호출

doctl에서 개별 기능은 유틸리티에 명령, 하나 이상의 하위 명령, 때로는 특정 값을 지정하는 하나 이상의 옵션을 제공하여 호출됩니다. 명령은 세 가지 주요 범주로 그룹화됩니다.

  • account 계정 관련 정보
  • auth DigitalOcean 인증
  • 인프라 관리를 위한 컴퓨팅

모든 명령의 개요를 보려면 doctl을 호출하면 됩니다. 세 가지 기본 범주 중 하나에서 사용 가능한 모든 명령을 보려면 doctl compute와 같은 doctl category를 사용할 수 있습니다. 특정 명령에 대한 사용 가이드를 보려면 doctl compute droplet --help에서와 같이 --help 플래그와 함께 명령을 입력하십시오.

JSON 형식의 데이터 검색

스크립팅 환경에서 또는 데이터 처리 도구를 사용하여 명령줄에서 작업할 때 명령에서 기계가 읽을 수 있는 출력을 얻는 것이 종종 도움이 됩니다.

기본적으로 doctl은 사람이 읽을 수 있는 텍스트 열로 출력 형식을 지정하지만 --output json 옵션을 사용하여 자세한 JSON 출력을 생성할 수 있습니다.

  1. doctl compute droplet get droplet_id --output json
Sample Output
{ "id": droplet_id, "name": "droplet_name", "memory": 1024, "vcpus": 1, "disk": 30, "region": { "slug": "nyc3", "name": "New York 3", "sizes": [ ...

대부분의 프로그래밍 언어에서 표준 라이브러리로 읽을 수 있는 형식 외에도 JSON 출력은 Droplet 및 기타 리소스를 보다 세밀하게 검사할 수 있습니다.

포맷팅

출력에서 필드 집합만 가져오는 것이 유용한 경우가 많습니다. 이렇게 하려면 --format 플래그 다음에 원하는 필드 목록을 사용할 수 있습니다. 예를 들어 Droplet의 ID, 이름 및 IP 주소만 얻으려면 다음 명령을 사용할 수 있습니다.

  1. doctl compute droplet list --format "ID,Name,PublicIPv4"
Sample output
ID Name Public IPv4 50513569 doctl-1 67.205.152.65 50513570 test 67.205.148.128 50513571 node-1 67.205.131.88

템플릿

doctl compute droplet get 명령은 출력 형식을 사용자 정의할 수 있는 출력 템플릿을 지원합니다. 이 기능을 사용하려면 --template 플래그를 통해 Go 형식 템플릿을 지정하세요.

예를 들어 droplet_name: droplet_name 형식으로 Droplet의 이름을 가져오려면 다음 get 명령을 사용합니다.

  1. doctl compute droplet get 12345678 --template "droplet_name: {{ .Name}}
Output
droplet_name: ubuntu-1gb-nyc3-01

리소스 작업

리소스 나열

Droplet과 같은 리소스 목록을 가져오려면 매개 변수 없이 list 명령을 사용할 수 있습니다.

  1. doctl compute droplet list
Sample output for list command
ID Name Public IPv4 Private IPv4 Public IPv6 Memory VCPUs Disk Region Image Status Tags 50513569 test-1 67.205.152.65 512 1 20 nyc1 Ubuntu 16.04.2 x64 active 50513571 test-2 67.205.131.88 512 1 20 nyc1 Ubuntu 16.04.2 x64 active 50513570 site 67.205.148.128 512 1 20 nyc1 Ubuntu 16.04.2 x64 active

list 명령은 glob을 선택적 매개변수로 지원합니다. glob은 이름별로 특정 리소스를 필터링하는 데 사용할 수 있는 와일드카드 문자로 패턴을 나타냅니다. 예를 들어 이름이 test로 시작하는 Droplet 목록을 가져오려면 다음 명령을 사용할 수 있습니다.

doctl compute droplet list 'test*'
Sample output for list command with 'doctl-' as glob
ID Name Public IPv4 Private IPv4 Public IPv6 Memory VCPUs Disk Region Image Status Tags 50513569 test-1 67.205.152.65 512 1 20 nyc1 Ubuntu 16.04.2 x64 active 50513571 test-2 67.205.131.88 512 1 20 nyc1 Ubuntu 16.04.2 x64 active

리소스 생성

리소스를 생성하려면 더 자세한 매개변수가 포함된 더 긴 명령이 필요합니다. Droplet을 생성하려면 관련 슬러그를 사용하여 사용하려는 이미지, 데이터 센터 영역 및 원하는 Droplet 종류를 지정해야 합니다. 액적 계획 변경에 대한 새 크기 슬러그 보기

예를 들어 다음 명령은 1GB 메모리, CPU 1개, SSH 키 및 백업이 활성화된 test라는 64비트 Debian 8 Droplet을 생성합니다.

  1. doctl compute droplet create test --size s-1vcpu-1gb --image debian-8-x64 --region nyc1 --ssh-keys 4d:23:e6:e4:8c:17:d2:cf:89:47:36:b5:c7:33:40:4e --enable-backups

다음 출력이 표시됩니다.

Sample Droplet creation output
ID Name Public IPv4 Memory VCPUs Disk Region Image Status 11450164 test 1024 1 30 nyc1 Debian 8.3 x64 new

리소스를 삭제하려면 인수로 리소스 ID가 필요하거나 지정된 리소스(예: 태그)에 ID가 존재하지 않는 경우 리소스 이름이 필요합니다. 의도를 확인하려면 확인 질문에 y 또는 로 답하여 모든 삭제 작업을 확인해야 합니다.

doctl compute droplet delete 123456
Output
Warning: Are you sure you want to delete droplet(s) (y/N) ?

답변을 제공하지 않거나 y 또는 와 다른 답변을 제공하면 리소스를 삭제하지 않고 작업이 취소됩니다. --f (--force) 플래그를 사용하여 명시적으로 제공하지 않고 doctl이 긍정 답변을 가정하도록 할 수 있습니다.

doctl compute droplet delete -f 123456

자원에 대한 고유 식별자 찾기

Droplet 생성 명령에는 NYC1 지역의 nyc1, debian-8-x64와 같은 일련의 식별자가 필요합니다. Debian 이미지의 경우 4d:23:e6:e4:8c:17:d2:cf:89:47:36:b5:c7:33:40:4e.

물방울 및 이미지와 같은 많은 리소스는 DigitalOcean의 데이터베이스 내에서 고유한 값(종종 숫자)으로 식별됩니다.

API에서 대부분의 명령에 필요한 고유 식별자를 얻을 수 있습니다.

Command Notes
doctl compute droplet list Your Droplets. Some commands also take the name; most require the numeric value from the ID column.
doctl compute ssh-key list The SSH keys associated with your account. For Droplet creation, you can specify either the numeric ID or fingerprint.
doctl compute region list Available regions. Use the string in the Slug column.
doctl compute image list Available images, including snapshots, backups, and base distribution images. Use the string in the Slug column for creating new Droplets.
doctl compute size list Available Droplet sizes. Use the string in the Slug column.
doctl compute tag list Available Tags. Use the string in the Name column.

물방울 작업

물방울 생성, 삭제 및 검사

doctl compute droplet 명령을 사용하면 Droplet을 생성, 삭제 및 검사할 수 있습니다. 다시 말하지만 개별 Droplet으로 작업하기 위한 대부분의 명령에는 Droplet의 고유 ID가 필요하며 이는 doctl droplet list의 출력에서 찾을 수 있습니다.

doctl compute droplet subcommand Notes
actions droplet_id Display a history of actions taken for a Droplet.
backups droplet_id List backups for a Droplet.
create name --size s-1vcpu-1gb --image image_slug --region nyc1 Create a Droplet. Size, image and region are all mandatory.
delete droplet_id_or_name Delete a Droplet by id or name.
get droplet_id Get details for a particular Droplet.
kernels droplet_id List kernels for a Droplet.
list List your current Droplets.
neighbors droplet_id List your Droplets running on the same physical hardware as a specific Droplet.
snapshots droplet_id List snapshots for a Droplet.
tag droplet_id/droplet_name Tag a Droplet.
untag droplet_id/droplet_name Untag a Droplet.

액적 작업 시작

doctl compute droplet-action 명령을 사용하면 전원 관리 작업과 백업 및 개인 네트워킹과 같은 토글 기능을 포함하여 Droplet에 대한 다양한 작업을 트리거할 수 있습니다.

doctl compute droplet-action subcommand Notes
get droplet_id --action-id action_id Get details about action on a Droplet.
disable-backups droplet_id Disable backups for a Droplet.
reboot droplet_id Reboot a Droplet.
power-cycle droplet_id Turn a Droplet off and back on again.
shutdown droplet_id Shut down a Droplet.
power-off droplet_id Power off a Droplet. The Droplet must be powered on. It’s usually best to do this from the command line of the Droplet itself in order to prevent data loss.
power-on droplet_id Power on a Droplet. The Droplet must be powered off.
power-reset droplet_id Power reset Droplet.
enable-ipv6 droplet_id Enable ipv6 for a Droplet.
enable-private-networking droplet_id Enable private networking for a Droplet.
upgrade droplet_id Upgrade a Droplet.
restore droplet_id --image-id image_id Restore a Droplet to a specific backup image. The image_id must be a backup of the Droplet.
resize droplet_id --size 2gb Resize a Droplet. The Droplet must be powered off. By default, disk is not resized, which allows Droplet to be downgraded. You can resize disk using the --resize-disk flag.
rebuild droplet_id --image-id image_id Rebuild a Droplet from a specific image.
rename droplet_id --droplet-name new_name Rename a Droplet to new_name.
change-kernel droplet_id --kernel-id kernel_id Change a Droplet’s kernel to kernel_id.
snapshot droplet_id --snapshot-name snapshot_name Take a snapshot of a Droplet, naming it snapshot_name.

SSH 작업

SSH 연결하기

SSH로 개별 Droplet에 연결하려면 일반적으로 IP 주소 또는 정규화된 도메인 이름을 알아야 합니다. 대신 doctl을 사용하여 이름, 숫자 ID 또는 개인 IP로 Droplet에 연결할 수 있습니다.

  1. doctl compute ssh droplet_name
  1. doctl compute ssh droplet_id
  1. doctl compute ssh --ssh-private-ip droplet_private_ip

또한 --ssh-command 플래그를 사용하여 SSH 연결이 설정되면 실행할 명령을 제공할 수 있습니다. 이렇게 하면 명령이 실행되고 출력이 로컬 터미널에 인쇄된 다음 SSH 세션이 닫힙니다.

  1. doctl compute ssh --ssh-command command

참고: SSH 명령 전달은 현재 Windows에서 사용할 수 없습니다.

기본 SSH 사용자 이름은 root(CoreOS의 경우 코어)이고 기본 포트는 22입니다. 플래그를 사용하여 기본값이 아닌 값을 설정하고 다른 기능을 활성화할 수 있습니다.

Flag Description
--ssh-user string User name to use for the SSH session.
--ssh-port int The port for the SSH session.
--ssh-key-path string Path to SSH key.
--ssh-agent-forwarding Enable agent forwarding.

구성 파일에서 기본 구성 값을 변경할 수도 있습니다. 프로젝트의 README 파일에는 이를 수행하는 방법에 대한 자세한 내용이 있습니다.

SSH 키 사용

doctl compute ssh-key 명령을 사용하여 계정과 연결된 SSH 공개 키를 관리할 수 있습니다. SSH 키를 참조하는 대부분의 명령은 키의 숫자 ID 또는 지문을 허용합니다.

doctl compute ssh-key subcommand Notes
list List SSH keys associated with your account.
get ssh_key_id_or_fingerprint Get info on a specific key, by numeric ID or key’s fingerprint.
create new_key_name --public-key "public_key" Associate a public key with your account by specifying its contents.
import new_key_name --public-key-file ~/.ssh/id_rsa.pub Associate a public key with your account by specifying a source file.
delete ssh_key_id_or_fingerprint Delete a key from your account by numeric ID or fingerprint.
update ssh_key_id_or_fingerprint --key-name new_key_name Change a key’s name by numeric ID or fingerprint.

유동 IP 작업

유동 IP는 Droplet 중 하나에 할당할 수 있는 공개적으로 액세스 가능한 고정 IP 주소입니다. 기능에 대한 자세한 설명은 DigitalOcean에서 유동 IP를 사용하는 방법을 참조하십시오. doctl compute floating-ip로 유동 IP를 조작할 수 있습니다.

doctl compute floating-ip subcommand Notes
list List all Floating IP addresses.
get floating_ip_address Get the details for a Floating IP address.
create --region nyc1 Create a Floating IP in nyc1 region.
delete floating_ip_address Delete a floating IP address.

Droplet에 유동 IP 할당

doctl compute floating-ip-action 명령은 Droplet에서 부동 IP를 할당하거나 할당 해제하는 데 사용됩니다.

doctl compute floating-ip-action subcommand Notes
assign floating_ip droplet_id Assign a Floating IP to the Droplet by its numeric ID.
unassign floating_ip Unassign a Floating IP.
get floating_ip action_id Get details about a Floating IP action by its numeric ID.

도메인 작업

doctl compute domain 명령은 도메인을 관리하는 데 사용됩니다. 주제에 대한 광범위한 개요는 DNS 관리 소개 시리즈를 참조하십시오.

doctl compute domain subcommand Notes
list List domains.
create domain_name --ip-address droplet_ip_address Create a domain with default records for droplet_ip_address.
get domain_name Get a domain record.
delete domain_name Delete a domain.

도메인 레코드 관리

doctl compute domain records 명령을 사용하여 도메인의 DNS 레코드에 대한 정보를 생성, 삭제, 업데이트 또는 가져올 수 있습니다.

doctl compute domain records subcommand Notes
list domain_name List records for given domain.
create domain_name --record-type record_type Create an record for domain.
delete domain_name record_id Delete record by numeric ID.
update domain_name --record-id record_id Update record by numeric ID.

블록 스토리지 볼륨 작업

블록 스토리지 볼륨 생성, 삭제 및 검사

doctl compute volume 명령을 사용하여 DigitalOcean의 Block Storage 볼륨에 대한 정보를 생성, 삭제 또는 가져올 수 있습니다. 이 기능에 대한 자세한 내용은 DigitalOcean에서 블록 스토리지를 사용하는 방법 가이드를 참조하세요.

doctl compute volume subcommand Notes
list List volumes.
create volume_name --region volume_region --size volume_size Create a volume. The name, region, and size are mandatory.
get volume_ID Get volume by numeric ID.
delete volume_ID Delete volume.
snapshot volume_ID Snapshot volume.

볼륨 작업 시작

doctl compute volume-action 명령을 사용하면 Droplet에 볼륨 연결 및 볼륨 분리를 포함하여 볼륨에 대한 작업을 트리거할 수 있습니다.

doctl compute volume-action subcommand Notes
attach volume_id droplet_id Attach a volume to a Droplet.
detach volume_id droplet_id Detach a volume from a Droplet.
resize volume_id --region volume_region --size new_size Resize a volume.

로드 밸런서 작업

doctl compute load-balancer 명령은 DigitalOcean의 로드 밸런서에 대한 정보를 생성, 삭제 또는 가져오는 데 사용할 수 있습니다. 이 기능에 대한 자세한 내용은 DigitalOcean 로드 밸런서 소개를 참조하십시오.

doctl compute load-balancer subcommand Notes
list List load balancers.
create --name lb_name --region lb_region --tag-name tag_name --forwarding-rules forwarding_rule Create a Load Balancer. The name, region, a tag or list of Droplet IDs, and at least one forwarding rule are mandatory.
update --name lb_name --region lb_region --tag-name tag_name --forwarding-rules forwarding_rule Create a Load Balancer. The name, region, a tag or list of Droplet IDs, and at least one forwarding rule are mandatory.
get lb_ID Get a load balancer.
delete lb_ID Delete a load balancer.
add-droplets lb_ID --droplet-ids droplet_ID Add Droplets to a load balancer.
remove-droplets lb_ID --droplet-ids droplet_ID Remove Droplets from a load balancer.
add-forwarding-rules lb_ID --forwarding-rules forwarding_rule Add forwarding rules to a load balancer.
remove-forwarding-rules lb_ID --forwarding-rules forwarding_rule Remove forwarding rules from a load balancer.

doctl에 대한 인수로 사용될 때 전달 규칙은 entry_protocol:protocol,entry_port:port,target_protocol:<와 같이 표현되어야 합니다. mark>프로토콜,target_port:포트.

인증서 관리

doctl compute certificate 하위 명령을 사용하면 SSL 인증서, 개인 키 및 인증서 체인을 업로드하고 관리할 수 있습니다.

doctl compute certificate subcommand Notes
list List all Certificates.
get certificate_id Get a Certificate by ID.
create --name certificate_name --leaf-certificate-path leaf_certificate_path Create a Certificate. Name and Leaf Certificate Path are mandatory.
delete certificate_id Delete a Certificate by ID.

스냅샷 작업

doctl compute snapshot 명령은 드롭릿 및 볼륨 스냅샷에 대한 정보를 나열, 삭제 또는 가져오는 데 사용할 수 있습니다.

doctl compute snapshot subcommand Notes
list List all Snapshots.
get snapshot_ID Get a Snapshot.
delete snapshot_ID Delete a Snapshot.

새 스냅샷을 생성하려면 해당 리소스 명령 트리에서 적절한 명령을 사용해야 합니다. 예를 들어:

  • doctl compute droplet-action snapshot droplet_ID는 Droplet에서 Snapshot을 생성합니다.
  • doctl 컴퓨팅 볼륨 스냅샷 volume_ID은 볼륨에서 스냅샷을 생성합니다.

이미지 작업

doctl compute image 명령을 사용하면 배포 이미지, 애플리케이션 이미지, 백업 및 스냅샷과 같은 사용자 생성 이미지를 포함한 모든 이미지를 관리할 수 있습니다. 자세한 정보를 제공하고 삭제 기능이 있으며 블록 스토리지 스냅샷을 지원하는 snapshot 명령을 사용하여 스냅샷을 관리하는 것이 좋습니다.

doctl compute image subcommand Notes
list --public List all images.
list-distribution --public List all available distribution images.
list-application --public List all available One-Click Applications.
list-user List all user-created images.
get image_id Get an Image by ID.
update image_id --name image_name Update Image’s name. Name is mandatory.
delete image_id Delete an Image by ID.

이미지 작업 호출

doctl compute image-action 명령을 사용하면 이미지를 전송하고 이미지에서 호출된 작업에 대한 세부 정보를 얻을 수 있습니다.

doctl compute image-action subcommand Notes
get image_id --action-id action_id Get an Action for Image by its ID. Action ID is mandatory.
transfer image_id --region region Transfer an Image to the another region. Image ID and region are mandatory.

방화벽 작업

doctl compute firewall 명령을 사용하면 규칙 생성 및 유지 관리를 포함하여 방화벽을 만들고 관리할 수 있습니다. doctl을 사용하여 방화벽을 관리하는 방법에 대한 자세한 내용은 Doctl을 사용하여 DigitalOcean 클라우드 방화벽으로 웹 서버 인프라를 보호하는 방법 자습서를 확인하십시오.

doctl compute firewall command Notes
list List all Firewalls.
list-by-droplet droplet_id List all Firewalls by Droplet’s numeric ID.
create --name firewall_name --inbound-rules inbound_rules --outbound-rules outbound_rules Create a Firewall. The name and at least an inbound or outbound rule are mandatory.
update firewall_id --name firewall_name --inbound-rules inbound_rules --outbound-rules outbound_rules Update a Firewall. The numeric ID, name and at least an inbound or outbound rule are mandatory.
get firewall_id Get a Firewall by its numeric ID.
delete firewall_id Delete a Firewall by numeric ID.
add-droplets firewall_id --droplet-ids droplet_IDs Add Droplets by their numeric ID to the Firewall.
remove-droplets firewall_id --droplet-ids droplet_IDs Remove Droplets from the Firewall by their numeric IDs.
add-tags firewall_id --tag-names tags Add Tags to the Firewall.
remove-tags firewall_id --tag-names tags Remove Tags from the Firewall.
add-rules firewall_id --inbound-rules inbound_rules --outbound-rules outbound_rules Add inbound or outbound rules to the Firewall.
remove-rules firewall_id --inbound-rules inbound_rules --outbound-rules outbound_rules Remove inbound or outbound rules to the Firewall.

doctl에 대한 인수로 사용될 때 인바운드 또는 아웃바운드 규칙은 protocol:protocol,ports:ports,droplet_id와 같이 표현되어야 합니다. :droplet-id.

태그 작업

태그는 리소스에 사용자 지정 레이블을 적용하는 데 사용되므로 리소스를 쉽게 필터링할 수 있습니다. DigitalOcean Droplets에 태그를 지정하는 방법 자습서에서 태그에 대해 자세히 알아볼 수 있습니다.

doctl compute tag subcommand Notes
create tag_name Create a Tag.
get tag_name Get a Tag by name.
list List all Tags.
delete tag_name Delete a Tag by name.

계정 작업

귀하의 계정에 대한 작업 기록 읽기

DigitalOcean 시스템은 Droplet, 유동 IP 및 기타 리소스에서 수행한 작업의 기록을 기록합니다. doctl compute action 명령을 사용하여 이 데이터에 액세스할 수 있습니다.

  1. doctl compute action list

다음과 같이 특정 Droplet에 대한 작업을 볼 수 있습니다.

  1. doctl compute droplet actions droplet_id

계정 정보 검색

구성된 이메일 주소 및 Droplet 한도와 같은 계정에 대한 기본 세부 정보를 찾을 수 있습니다.

  1. doctl account get

API 요청에는 비율이 제한되어 있으므로 최근에 수행한 요청 수와 한도가 재설정되는 시기를 확인하는 것이 도움이 될 수 있습니다.

  1. doctl account ratelimit

결론

doctl 유틸리티는 명령줄에서 Droplet 및 기타 리소스를 관리하는 데 유용한 도구입니다. 일상적인 개발 및 관리 작업에 필요한 웹 기반 인터페이스와의 수동 상호 작용의 양을 크게 줄일 수 있습니다.

시스템 수준 작업을 자동화하기 위한 Ansible과 같은 도구에 대해 배우는 것 외에도.