//
Search
Duplicate
πŸ˜†

Docker Container Use Command

Launching a Container Run a container
$ docker run <image>
Shell
볡사
run은 exec와 λΉ„μŠ·ν•œ μ—­ν™œμ„ μ‹€ν–‰ν•˜μ§€λ§Œ λ‹€λ₯Έ 점은 μ»¨ν…Œμ΄λ„ˆ μž¬μ‹€ν–‰ μ—¬λΆ€μž…λ‹ˆλ‹€. run은 μ‹€ν–‰μ‹œμ— μƒˆλ‘œμš΄ μ»¨ν…Œμ΄λ„ˆλ₯Ό λ„μš°λŠ” 반면 execλŠ” μ‹€ν–‰λ˜μ–΄ μžˆλŠ” μ»¨ν…Œμ΄λ„ˆμ— μ ‘μ†ν•©λ‹ˆλ‹€. execλŠ” ν”„λ‘œμ„ΈμŠ€λ₯Ό μ‹€ν–‰μ‹œμΌœ 놓을 λ•Œ μ‚¬μš©λ˜κ³  run은 batch μž‘μ—…μ— νŠΉν™”λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. Run container and drop to shell
$ docker run -it <image>
Shell
볡사
-i ν‘œμ€€ μž…λ ₯(stdin)을 ν™œμ„±ν™”ν—ˆλ©° μ»¨ν…Œμ΄λ„ˆμ™€ μ—°κ²°λ˜μ–΄ μžˆμ§€ μ•Šλ”λΌλ„ ν‘œμ€€ μž…λ ₯을 μœ μ§€ν•©λ‹ˆλ‹€. -t TTY λͺ¨λ“œλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. Shell을 μ‚¬μš©ν•˜λ €λ©΄ 이 μ˜΅μ…˜μ„ μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.
$ docker run --interactive --tty <image>
Shell
볡사
Run container in backgrand
$ docker run -d <image>
Shell
볡사
Container restart settings
$ docker run --restart (always|no|on-failure[:maxretries][unless-stopped) <image>
Shell
볡사
Remove container when exited
$ docker run --rm <image>
Shell
볡사
Provide container nickname
$ docker run --name <name> <image>
Shell
볡사
Accessing the Container Start a container
$ docker start <container>
Shell
볡사
Run a command against a container
$ docker exec <container> <command>
Shell
볡사
Drop into a shell
$ docker exec -it <container> <shell>
Shell
볡사
Copy file to container / copy container file to localhost
$ docker cp <source> <container>:<destination> $ docker cp <container>:<source> <destination>
Shell
볡사
Container Management Stop and restart a container
$ docker stop <container> $ docker restart <container>
Shell
볡사
Remove a container
$ docker rm <container>
Shell
볡사
Remove all stopped containers
$ docker container prune
Shell
볡사
docker 였브젝트 가비지 μ»¬λ ‰μ…˜ κΈ°λŠ₯이라고 μƒκ°ν•˜λ©΄ μ‰½μŠ΅λ‹ˆλ‹€. μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” container 일괄 μ‚­μ œν•©λ‹ˆλ‹€. Rename a container
$ docker rename <container> <new-name>
Shell
볡사
View container metrics
$ docker stats [<container>]
Shell
볡사
Publishing the Container View container information
$ docker inspect <container>
Shell
볡사
container에 λŒ€ν•œ μ„ΈλΆ€ 정보 확인을 ν•  수 μžˆμŠ΅λ‹ˆλ‹€. Create a container image
$ docker commit <container> <name>
Shell
볡사
container μƒμ—μ„œ μž‘μ—…ν•œ λ‚΄μš©μ„ μ΄λ―Έμ§€λ‘œ commit ν•  수 있고 λ‚˜μ€‘μ— λ‹€μ‹œ containerλ₯Ό μ‹±ν–‰ν•˜λ―€λ‘œμ¨ μž‘μ—…ν–ˆλ˜ λ‚΄μš©μ„ λ‹€μ‹œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.