·터미널 명령어

docker run

패키지·런타임

쓰는 꼴

docker run [-d] [-p <host>:<container>] <image> [command]

이미지에서 컨테이너를 새로 만들어 띄웁니다 — 두 번 치면 컨테이너가 둘이 되니 멈춘 것을 다시 켜는 일은 docker start이고, -p 없이는 host에서 닿지 않으며 -v 없이 쓴 것은 컨테이너와 함께 사라집니다.

자주 쓰는 옵션

옵션
-drun in the background and print the id
-p 8080:80publish a container port on the host
-itinteractive with a terminal, for a shell
--rmdelete the container when it exits
-v <host>:<path>mount a host folder or named volume
-e KEY=valueset an environment variable
--name <name>give it a name instead of a random one
--network <net>attach it to a network

예시

docker run --rm -it ubuntu bash

a throwaway shell in a container

docker run -d -p 8080:80 --name web nginx

nginx in the background, reachable on localhost:8080

docker run --rm -v "$PWD":/app -w /app node:22 npm test

runs your tests in a container without installing node

무엇을 어디에 넣는지가 문제입니다. 프로젝트 안인지 시스템 전체인지 먼저 정하세요.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. docker run은 무엇을 하나요?

이미지에서 컨테이너를 새로 만들어 띄웁니다 — 두 번 치면 컨테이너가 둘이 되니 멈춘 것을 다시 켜는 일은 docker start이고, -p 없이는 host에서 닿지 않으며 -v 없이 쓴 것은 컨테이너와 함께 사라집니다.

Q. 어떻게 치나요?

docker run [-d] [-p <host>:<container>] <image> [command] — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 8개입니다. 전체 목록은 man docker에 있습니다. 이 명령은 패키지·런타임 갈래입니다.

같이 보는 명령

man 페이지: man docker-run