엔드포인트가 움직일 때 복구하기
엔드포인트가 움직일 때 복구하기
재시작이나 연결 변경 후 샌드박스 핸들을 새로고침해 봐요. 샌드박스가 같은 리소스 이름을 유지하더라도 저장된 주소는 오래될 수 있어요.
출처: 문서
본문
애플리케이션이 이미 보유한 핸들로 시작하세요. 그 이름과 UID를 유지하고, 다른 샌드박스의 정체성으로 교체하지 마세요.
현재 엔드포인트 비교
핸들을 새로고침한 뒤 이전과 새 연결 정보를 비교해요. SDK는 새로고침된 핸들을 구성하면서 리소스 정체성을 확인해요.
예시는 엔드포인트가 변경되었는지 보고하고 새로고침된 핸들을 반환해요. 이후 프로세스와 파일 호출에 그 핸들을 사용하세요.
핵심 코드:
const current = await held.refresh();
const before = held.core.endpoint;
const after = current.core.endpoint;
return {
moved:
before?.uri !== after?.uri || before?.protocol !== after?.protocol,
current,
};
완전한 TypeScript 예시: rebind/detect.ts
import type { Sandbox } from '@docker/sandboxes';
export async function endpointMoved(held: Sandbox) {
const current = await held.refresh();
const before = held.core.endpoint;
const after = current.core.endpoint;
return {
moved:
before?.uri !== after?.uri || before?.protocol !== after?.protocol,
current,
};
}
새로고침된 핸들로 실행
새 프로세스 연결을 열기 전에 새로고침하세요. SDK가 현재 엔드포인트에 적합한 샌드박스 자격 증명을 얻어요. 애플리케이션이 거기에 Docker 계정 토큰을 전달할 필요가 없어요.
이 예시는 새로고침 후 새 작업을 시작해요. 완료가 알려지지 않은 명령을 재생하지는 않아요. 이전 명령이 여전히 실행 중일 수 있다면 먼저 그것을 찾아 다시 연결하세요.
핵심 코드:
const current = await held.refresh();
return current.processes.run({ args }, { timeoutMs: 300_000 });
완전한 TypeScript 예시: rebind/rebuild.ts
import type { Sandbox } from '@docker/sandboxes';
export async function runAndRebind(held: Sandbox, args: string[]) {
const current = await held.refresh();
return current.processes.run({ args }, { timeoutMs: 300_000 });
}