인프런 subicura님의 도커 기초 강의를 듣고 정리한 내용임을 미리 밝혀둡니다.
지난 포스팅에서는 docker run 명령어가 가장 많이 사용되기 때문에 관련 명령어부터 살펴보았다.
https://steady-programming.tistory.com/23
[Docker] #3 docker run 명령어
도커는 프로세스를 독립된 컨테이너에서 실행한다. docker run 명령어가 실행되면 컨테이너 프로세스는 독립된 환경에서 그것만의 파일 시스템, 네트워킹, 그리고 host로부터 분리된 프로세스 구조
steady-programming.tistory.com
이번 포스팅에서는 docker run 이외에 많이 쓰이는 명령어 중심으로 정리를 하고자 한다.
ps 명령어
리눅스의 ps와 동일한 기능으로, 실행중인 컨테이너 목록을 확인할 수 있다.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
961d3eccb128 ubuntu:20.04 "bash" 55 minutes ago Up 55 minutes romantic_booth
42928841e046 mariadb:10.9 "docker-entrypoint.s…" 56 minutes ago Up 56 minutes 3306/tcp, 0.0.0.0:3308->3308/tcp mysql
-a를 이용해서 이전에 종료된 컨테이너 이력까지 확인할 수 있다.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
babfb97869c3 python:3.8-alpine "env" 53 minutes ago Exited (0) 53 minutes ago relaxed_mclaren
9cea92099315 ubuntu:20.04 "bash" About an hour ago Exited (0) 58 minutes ago TAG
961d3eccb128 ubuntu:20.04 "bash" About an hour ago Up About an hour romantic_booth
42928841e046 mariadb:10.9 "docker-entrypoint.s…" About an hour ago Up About an hour 3306/tcp, 0.0.0.0:3308->3308/tcp mysql
a6afae72a5a7 ubuntu:20.04 "bash" 3 hours ago Exited (0) 3 hours ago ubuntu_wtout_rm
8003c692fcb3 ubuntu:20.04 "/bin/bash" 3 hours ago Exited (0) 3 hours ago inspiring_darwin
edded841c8e8 ubuntu:20.04 "/bin/bash" 3 hours ago Exited (0) 3 hours ago nervous_williams
stop 명령어
실행중인 컨테이너를 중지하는 명령어이다.
$ docker stop mysql romantic_booth
mysql
romantic_booth
띄어쓰기를 통해 여러 컨테이너를 중지할 수 있다.
rm 명령어
--rm 옵션으로 컨테이너를 실행하지 않으면 컨테이너가 종료되어도 찌꺼기가 남을 수 있는데 이를 제거하는 명령어이다.
$ docker rm mysql romantic_booth
mysql
romantic_booth
logs 명령어
-f, --tail 옵션을 통해 로그의 처음과 끝 부분을 확인할 수 있다.
$ docker run -d --rm -p 3308:3308 \
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \
--name mysql \
mariadb:10.9
e3aeba16a80d7ff00ccbdd5c250e226b96d2002d73e4b057cb21ff33e2c715d7
$ docker logs mysql
2022-11-10 05:50:52+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.9.3+maria~ubu2204 started.
2022-11-10 05:50:53+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-11-10 05:50:53+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.9.3+maria~ubu2204 started.
2022-11-10 05:50:53+00:00 [Note] [Entrypoint]: Initializing database files
2022-11-10 5:50:53 0 [Warning] mariadbd: io_uring_queue_init() failed with ENOMEM: try larger memory locked limit, ulimit -l, or https://mariadb.com/kb/en/systemd/#configuring-limitmemlock under systemd (262144 bytes required)
2022-11-10 5:50:53 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF
...
images 명령어
다운로드한 도커 이미지를 확인하는 명령어이다.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb 10.9 cfe889c390f2 7 days ago 366MB
python 3.8-alpine 6690c9c6e607 2 weeks ago 46.1MB
pull 명령어
이미지를 다운로드하는 명령어이다.
$ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
a217cb16e35b: Pull complete
Digest: sha256:ca70a834041dd1bf16cc38dfcd24f0888ec4fa431e09f3344f354cf8d1724499
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
rmi 명령어
다운로드한 이미지를 삭제하는 명령어이다.
$ docker rmi ubuntu:18.04
Untagged: ubuntu:18.04
Untagged: ubuntu@sha256:ca70a834041dd1bf16cc38dfcd24f0888ec4fa431e09f3344f354cf8d1724499
Deleted: sha256:2d07c6c16e27165868ba97bf864de4efbb4464dc41e30eb7c5245294097a7370
Deleted: sha256:7e52d6f76a698aca1141c602a033d19bfc5250542801304c443b13e096d5390f
'Devops > docker' 카테고리의 다른 글
[Docker] #5 docker-compose (0) | 2022.11.10 |
---|---|
[Docker] #3 docker run 명령어 (0) | 2022.11.10 |
[Docker] #2 Docker vs Virtual Machine (0) | 2022.11.09 |
[Docker] #1 도커란 무엇인가 (0) | 2022.11.09 |
댓글