본문 바로가기

TroubleShooting/Docker

docker 간단 명령어 정리 on CentOS 7

728x90

docker 간단 명령어 정리(centOS 7)


- 도커 이미지 실행

# docker run hello-world


Hello from Docker!

This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:

 https://cloud.docker.com/


For more examples and ideas, visit:

 https://docs.docker.com/engine/userguide/



# docker run -it centos bash

[root@8f65e72cb233 /]#

[root@8f65e72cb233 /]# ls


-> centos 쉘(bash) 을 실행시켜서 파일 목록이나 디렉토리 구조를 확인할 수 있다. centos 이미지가 없을 경우에는 자동으로 docker hub 에서 download 한다.(pull)


- 도커 이미지들 확인

# docker images

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE

docker.io/ubuntu        latest              ccc7a11d65b1        3 weeks ago         120.1 MB

docker.io/centos        latest              328edcd84f1b        4 weeks ago         192.5 MB

docker.io/hello-world   latest              1815c82652c0        11 weeks ago        1.84 kB

-> 다운받은 도커 이미지 파일들은 /var/lib/docker/image/ 에 존재한다. (CentOS 인 경우)

 

 아래 화면에서 보면 image/devicemapper 디렉토리에 distribution, imagedb, layerdb, repositories 이다.

# pwd

/var/lib/docker/image/devicemapper

# ls -la

합계 4

drwx------. 5 root root  77  9월  6 18:14 .

drwx------. 3 root root  25  9월  5 17:25 ..

drwx------. 4 root root  56  9월  5 17:26 distribution

drwx------. 4 root root  35  9월  5 17:25 imagedb

drwx------. 5 root root  42  9월  5 17:26 layerdb

-rw-------. 1 root root 891  9월  6 18:14 repositories.json

# ls

distribution  imagedb  layerdb  repositories.json

# more repositories.json | python -mjson.tool

{

    "Repositories": {

        "docker.io/centos": {

            "docker.io/centos:latest": "sha256:328edcd84f1bbf868bc88e4ae37afe421ef19be71890f59b4b2d8ba48414b84d",

            "docker.io/centos@sha256:26f74cefad82967f97f3eeeef88c1b6262f9b42bc96f2ad61d6f3fdf544759b8": "sha256:328edcd84f1bbf868bc88e4ae37afe421ef19be71890f59b4b2d8ba48414b84d"

        },

        "docker.io/hello-world": {

            "docker.io/hello-world:latest": "sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57",

            "docker.io/hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f": "sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57"

        },

        "docker.io/ubuntu": {

            "docker.io/ubuntu:latest": "sha256:ccc7a11d65b1b5874b65adb4b2387034582d08d65ac1817ebc5fb9be1baa5f88",

            "docker.io/ubuntu@sha256:34471448724419596ca4e890496d375801de21b0e67b81a77fd6155ce001edad": "sha256:ccc7a11d65b1b5874b65adb4b2387034582d08d65ac1817ebc5fb9be1baa5f88"

        }

    }

}



- 도커 실행 컨테이너 확인

# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@235 ~]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES

8f65e72cb233        centos              "bash"              8 minutes ago       Exited (127) 2 minutes ago                       mad_torvalds

33a6167a4bf4        centos              "bash"              8 minutes ago       Exited (0) 8 minutes ago                         adoring_swartz

1fc2f1ecd64a        centos              "bash"              9 minutes ago       Exited (0) 9 minutes ago                         high_carson

4d30dc88962b        centos              "bash"              9 minutes ago       Exited (0) 9 minutes ago                         peaceful_heyrovsky

e2cbdcbabf11        ubuntu              "bash"              10 minutes ago      Exited (0) 10 minutes ago                        high_darwin

2fee380d8bce        ubuntu              "bash"              10 minutes ago      Exited (0) 10 minutes ago                        berserk_lovelace

74cbada0927a        hello-world         "/hello"            12 minutes ago      Exited (0) 12 minutes ago                        backstabbing_poincare

135bae3e7596        hello-world         "bash"              12 minutes ago      Created                                          hungry_ramanujan

bd6680e5cdd8        hello-world         "/usr/bin/bash"     12 minutes ago      Created                                          compassionate_murdock

ce192cbf35b2        centos              "bash"              3 hours ago         Exited (0) 3 hours ago                           pensive_mcnulty


- 도커 컨테이너 삭제

# docker rm mad_torvalds adoring_swartz high_carson peaceful_heyrovsky high_darwin berserk_lovelace backstabbing_poincare hungry_ramanujan compassionate_murdock pensive_mcnuty

mad_torvalds

adoring_swartz

high_carson

peaceful_heyrovsky

high_darwin

berserk_lovelace

backstabbing_poincare

hungry_ramanujan

compassionate_murdock

pensive_mcnulty

-> docker ps 명령어 에서 NAMES 열에 있던 이름(컨테이너 실행시(docker run) --name 옵션을 안줘서 자동으로 생성된 이름이 보인다.)으로 해당 컨테이너들을 삭제한다. 하나만 입력해도 되고 여러개를 입력해도 된다.


- 도커 이미지 삭제

# docker images

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE

docker.io/ubuntu        latest              ccc7a11d65b1        3 weeks ago         120.1 MB

docker.io/centos        latest              328edcd84f1b        4 weeks ago         192.5 MB

docker.io/hello-world   latest              1815c82652c0        11 weeks ago        1.84 kB

[root@235 ~]# docker rmi ccc7a11d65b1

Untagged: docker.io/ubuntu:latest

Untagged: docker.io/ubuntu@sha256:34471448724419596ca4e890496d375801de21b0e67b81a77fd6155ce001edad

Deleted: sha256:ccc7a11d65b1b5874b65adb4b2387034582d08d65ac1817ebc5fb9be1baa5f88

Deleted: sha256:cb5450c7bb149c39829e9ae4a83540c701196754746e547d9439d9cc59afe798

Deleted: sha256:364dc483ed8e64e16064dc1ecf3c4a8de82fe7f8ed757978f8b0f9df125d67b3

Deleted: sha256:4f10a8fd56139304ad81be75a6ac056b526236496f8c06b494566010942d8d32

Deleted: sha256:508ceb742ac26b43bdda819674a5f1d33f7b64c1708e123a33e066cb147e2841

Deleted: sha256:8aa4fcad5eeb286fe9696898d988dc85503c6392d1a2bd9023911fb0d6d27081


-> ubuntu 이미지를 지우기 위해 image ID 를 확인후, 해당 id 값으로 삭제한다.


참고한 사이트 :

http://pyrasis.com/Docker/Docker-HOWTO

'TroubleShooting > Docker' 카테고리의 다른 글

도커 데스크탑 데이터 삭제  (0) 2023.08.18
flutter Android toolchain 문제 해결  (1) 2023.06.18
도커 데스크탑 디렉토리 이동  (1) 2023.03.24
docker logs 파일로 저장  (0) 2022.11.30
docker 컨테이너 IP 주소  (0) 2017.09.05