본문으로 건너뛰기

CLI

docker attach

Attach local standard input, output, and error streams to a running container

 docker attach [OPTIONS] CONTAINER

docker build

Build an image from a Dockerfile

  • 레퍼런스
  • -t 옵션을 사용하지 않으면 16진수 형태의 이름으로 이미지가 만들어지므로 가급적 -t 옵션을 사용하자

Usage

docker build [OPTIONS] PATH | URL | -

Options

OptionsDescription
--build-argSet build-time variables
--tag , -tName and optionally a tag in the ‘name:tag’ format
--rmRemove intermediate containers after a successful build
--file , -fName of the Dockerfile (Default is ‘PATH/Dockerfile’)

예시

docker build -t neptunes032/react-test-app -f ./frontend/Dockerfile.dev ./frontend
docker build -t neptunes032/docker-frontend ./frontend
docker build .

docker commit

Create a new image from a container’s changes

Usage

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Options

Name, shorthandDefaultDescription
--author , -aAuthor (e.g., "John Hannibal Smith [hannibal@a-team.com>])
--change , -cApply Dockerfile instruction to the created image
--message , -mCommit message
--pause , -ptruePause container during commit

예시

##  c3f279d17e0a 컨테이너를 svendowideit/testimage:version3라는 이름을 가지는 이미지로 만든다
docker commit c3f279d17e0a svendowideit/testimage:version3
## 새로운 환경변수 ENV DEBUG=true를 가지는 이미지를 생성한다
docker commit --change "ENV DEBUG=true" c3f279d17e0a svendowideit/testimage:version3

docker container ls

List containers

docker container ls [OPTIONS]

docker container prune

Remove all stopped containers

docker container prune [OPTIONS]
OptionsDescripton
--filterProvide filter values (e.g. ‘until=')
--force , -fDo not prompt for confirmation

docker container rm

Remove one or more containers

docker container rm [OPTIONS] CONTAINER [CONTAINER...]

docker create

Create a new container

  • 레퍼런스
  • 새로운 컨테이너를 생성만 하며 시작하지 않는다.
  • 생성된 컨테이너는 docker start 명령어를 통해 시작시킨다.

docker cp

Copy files/folders between a container and the local filesystem

 docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

예시

##  로컬 파일 시스템의 /Users/YT/Downloads/license.xml 파일을 tibero(컨테이너 이름) 컨테이너의 /usr/local/ 위치로 복사
docker cp /Users/YT/Downloads/license.xml tibero:/usr/local/

docker exec

Run a command in a running container

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
OptionsDescripton
--detach , -dDetached mode: run command in the background
--detach-keysOverride the key sequence for detaching a container
--env , -eSet environment variables
--interactive , -iKeep STDIN open even if not attached
--privilegedGive extended privileges to the command
--tty , -tAllocate a pseudo-TTY
--user , -uUsername or UID (format: <name|uid>[:<group|gid>])
--workdir , -wWorking directory inside the container

예시

docker exec -it jenkins /bin/bash

docker images

List images

docker images [OPTIONS] [REPOSITORY[:TAG]]

docker image ls

List images

docker image ls [OPTIONS] [REPOSITORY[:TAG]]

docker image prune

Remove unused images

docker image prune [OPTIONS]
OptionsDescription
--all , -aRemove all unused images, not just dangling ones
--filterProvide filter values (e.g. ‘until=')
--force , -fDo not prompt for confirmation

docker image rm

Remove one or more images

docker image rm [OPTIONS] IMAGE [IMAGE...]

예시

##  모든 이미지 삭제
docker image rm $(docker images -q)

docker inspect

Return low-level information on Docker objects

docker inspect [OPTIONS] NAME|ID [NAME|ID...]
OptionsDefaultDescription
--format , -fFormat the output using the given Go template
--size , -sDisplay total file sizes if the type is container
--typeReturn JSON for specified type

예시

##  인스턴스 ip 조회
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID

docker load

Load an image from a tar archive or STDIN

Usage

$ docker load [OPTIONS]

docker logs

Fetch the logs of a container

docker logs [OPTIONS] CONTAINER
OptionsDescription
--follow , -fFollow log output
--tailNumber of lines to show from the end of the logs
--timestamps , -tShow timestamps

docker network ls

List networks

docker network ls [OPTIONS]

docker network connect

Connect a container to a network

docker network connect [OPTIONS] NETWORK CONTAINER

docker network create

Create a network

docker network create [OPTIONS] NETWORK
OptionsDefaultDescription
--driver , -dbridgeDriver to manage the Network
--gatewayIPv4 or IPv6 Gateway for the master subnet
--ip-rangeAllocate container ip from a sub-range
--subnetSubnet in CIDR format that represents a network segment

예시

##  bridge 드라이버 네트워크 생성
docker network create --driver bridge network-name

##
docker network create --driver bridge \
--subnet 172.72.0.0/16 \
--ip-range 172.72.0.0/24 \
--gateway 172.72.0.1 \
custom_network

docker network disconnect

Disconnect a container from a network

docker network disconnect [OPTIONS] NETWORK CONTAINER

docker ps

List containers

docker ps [OPTIONS]
OptionsDescription
--all , -aShow all containers (default shows just running)
--quiet , -qOnly display numeric IDs

예시

// 모든 컨테이너 삭제
docker rm `docker ps -a -q`

docker pull

Pull an image or a repository from a registry

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

docker push

Push an image or a repository to a registry

docker push [OPTIONS] NAME[:TAG]

docker run

Run a command in a new container

Usage

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Options

OptionsDescription
--attach , -aAttach to STDIN, STDOUT or STDERR
--detach , -dRun container in background and print container ID
--env , -eSet environment variables
--interactive , -iKeep STDIN open even if not attached
--publish , -pPublish a container’s port(s) to the host
--publish-all , -PPublish all exposed ports to random ports
--rmAutomatically remove the container when it exits
--volume , -vBind mount a volume
--tty , -tAllocate a pseudo-TTY

예시

docker run -e CI=true neptunes032/react-test-app npm run test
docker run -p 3000:80 -d --name feedback-app --rm feedback-node

Publish or expose port (-p, --expose)

This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. You can also specify udp and sctp ports. The Docker User Guide explains in detail how to manipulate ports in Docker.

docker run -p 127.0.0.1:80:8080/tcp ubuntu bash

docker rm

Remove one or more containers

docker rm [OPTIONS] CONTAINER [CONTAINER...]
OptionsDescription
--force , -fForce the removal of a running container (uses SIGKILL)
--link , -lRemove the specified link
--volumes , -vRemove anonymous volumes associated with the container

예시

##  모든 도커 컨테이너 제거
docker rm $(docker ps -a -q)
## 모든 정지된 컨테이너 삭제
docker rm $(docker ps --filter status=exited -q)

docker save

Save one or more images to a tar archive (streamed to STDOUT by default)

  • 레퍼런스
  • 이미지를 단일 바이너리 파일로 저장하고 docker load 명령어를 통해 단일 바이너리 파일을 다시 도커에 로드한다.

Usage

$ docker save [OPTIONS] IMAGE [IMAGE...]

Search the Docker Hub for images


docker start

Start one or more stopped containers

docker start [OPTIONS] CONTAINER [CONTAINER...]

docker stop

Stop one or more running containers

docker stop [OPTIONS] CONTAINER [CONTAINER...]
Name, shorthandDefaultDescription
--time , -t10Seconds to wait for stop before killing it

예시

##  구동중인 모든 컨테이너 중지
docker stop $(docker ps -a -q)

docker tag

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

참고