docker run ↔ Compose
docker run 명령을 compose.yaml 서비스로, Compose 서비스를 다시 docker run 명령으로 변환합니다. 포트·환경 변수·볼륨·마운트·네트워크·재시작 정책·명령을 그대로 옮기고, Compose로 표현할 수 없는 플래그는 참고로 알려 줍니다.
브라우저 안에서만 실행됩니다. 입력한 내용은 어디에도 업로드되지 않습니다.
양방향 변환이 모두 이 브라우저 탭 안에서 실행되며, 붙여 넣은 내용은 어디로도 전송되지 않습니다.
services:
blog-db:
image: postgres:16-alpine
container_name: blog-db
ports:
- "5432:5432"
environment:
POSTGRES_USER: blog
POSTGRES_PASSWORD: change-me
POSTGRES_DB: blog
volumes:
- blog-db-data:/var/lib/postgresql/data
restart: unless-stopped
volumes:
blog-db-data:compose.yaml로 저장하고 docker compose up -d로 실행하세요.
docker run → Compose 치트시트
빠른 참조- docker run -d --name web -p 3000:3000 image
- 이미지는 플래그가 아닌 첫 인자이고, 그 뒤의 모든 인자는 Compose의 command:로 들어갑니다.
- -p 8080:80
- Compose는 같은 값을 ports: 아래 host:container로 나눠 쓰며, 127.0.0.1:8080:80처럼 앞에 붙은 호스트 IP도 그대로 유지합니다.
- -e KEY=VALUE
- 반복한 -e 플래그는 environment 맵이 됩니다. 값 없는 -e KEY가 하나라도 있으면 호스트에서 보간하는 목록 형식으로 바뀝니다.
- -v name:/path
- 이름 있는 볼륨은 Compose가 대신 써 주는 최상위 volumes: 항목도 필요하고, /나 .으로 시작하는 경로는 바인드 마운트가 됩니다.
- --restart unless-stopped
- 재시작 정책은 그대로 옮겨지지만, docker run의 --rm과 달리 Compose는 서비스를 restart: "no"로 멈춥니다.
- docker compose up -d
- docker run 명령을 대신하는 실행 방법입니다. Compose는 서비스를 백그라운드로 띄우므로 파일에는 -d가 없습니다.
자주 묻는 질문
도구 아래에서 답을 확인하세요플래그가 참고 목록으로 빠진 이유는 무엇인가요?
--rm이나 --pull처럼 compose.yaml에 대응이 없는 플래그는 조용히 지우지 않고 목록으로 알려 줍니다.
볼륨은 어떻게 변환되나요?
이름 있는 볼륨은 최상위 volumes: 항목까지 함께 만들고, /나 .으로 시작하는 경로는 바인드 마운트가 됩니다.
compose.yaml에서 docker run으로 되돌릴 수 있나요?
가능합니다. 서비스마다 포트, 환경 변수, 볼륨, 네트워크, 재시작 정책을 담은 docker run 명령 하나가 됩니다.
Docker 관련 문법 가이드
Docker 가이드 전체Docker: exec user process caused: exec format error
An arm64 image on an amd64 host is a runtime failure, not a pull failure. Diagnose the platform, build for the target, publish multi-arch, and spot the script variant.
DockerDocker Compose: bind: address already in use and Port Conflicts
A published port is a host socket, and two projects cannot own it. How to find the real owner, why an override file merged instead of replacing, and how to publish dynamically.
DockerAlpine musl vs Debian slim: DNS Timeouts and Native Builds
musl rejects manylinux wheels and linux-x64-gnu prebuilds, so the installer starts compiling without a toolchain. And ndots:5 in Kubernetes adds five seconds per lookup.
DockerDocker Compose Connection Refused: localhost vs Service DNS
localhost inside a container is that container. Compose resolves service names on a shared network, depends_on does not wait for readiness, and binding loopback breaks the rest.