도커 명령어
1. docker search
■ 도커 이미지 목록 조회(docker hub에서 사용가능 한 docker image 목록을 가져옴)
- STARS : 별점(평점)
■ search 옵션
- 상위 몇 개 정도만 조회할 때 : docker search tomcat –limit 5
- 이미지 중 별점 100이상 조회할 때 : docker search tomcat --filter=stars=100
■ 도커 이미지 검색
[root@localhost ~]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 2935 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 86 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base… 55 [OK]
bitnami/tomcat Bitnami Tomcat Docker Image 37 [OK]
kubeguide/tomcat-app Tomcat image for Chapter 1 29
consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 18 [OK]
cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 13 [OK]
arm32v7/tomcat Apache Tomcat is an open source implementati… 10
rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl… 6 [OK]
maluuba/tomcat7-java8 Tomcat7 with java8. 6
unidata/tomcat-docker Security-hardened Tomcat Docker container. 5 [OK]
arm64v8/tomcat Apache Tomcat is an open source implementati… 3
amd64/tomcat Apache Tomcat is an open source implementati… 2
jelastic/tomcat An image of the Tomcat Java application serv… 2
cfje/tomcat-resource Tomcat Concourse Resource 2
ppc64le/tomcat Apache Tomcat is an open source implementati… 1
picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAGER… 1 [OK]
camptocamp/tomcat-logback Docker image for tomcat with logback integra… 1 [OK]
chenyufeng/tomcat-centos tomcat基于centos6的?像 1 [OK]
oobsri/tomcat8 Testing CI Jobs with different names. 1
99taxis/tomcat7 1 [OK]
2. docker pull / images
■ 도커 이미지 내려 받기 - STARS : 별점(평점)
- latest : 마지막 버전 내려 받기
- tomcat:9.0 : 특정 버전 내려 받기(tomcat 9.0)
■ 도커 이미지 내려 받기
[root@localhost ~]# docker pull tomcat:latest
Latest: Pulling from library/tomcat
B9a857cbf04d: Pull complete
D557ee20540b: Pull complete
3b9ca4f00c2e: Pull complete
667fd949ed93: Pull complete
B6a945768a17: Pull complete
Aa2f45feafbf: Pull complete
7179e0e40c20: Pull complete
d659cf2d36fd: Pull complete
de2ad1203c1c: Pull complete
5cfec769b96c: Pull complete
Digest: sha256:a84de325cae4a64b143d8fd3b20761ce44d01388b6ba1ed7ea877cbd0f9701bc
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@localhost ~]#
■ 도커 다운로드 된 이미지 조회
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 66d886628b2a 6 days ago 668MB
3. docker run
■ Docker run 커멘드의 기본 포맷(이미지 식별자는 필수)
[root@localhost ~]# docker run (<옵션>) <이미지실별자> (<명령어>) (<인자>)
■ 컨테이너 실행
[root@localhost ~]# docker run -i -t -d -p 3306:3306 build_mar2
b20430bb3c3c2c1373b3c8718f0230d2fcae726afbb3d3013729b7ef3b5602d3
■ 컨테이너 실행 확인
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b20430bb3c3c build_mar2 "/root/mariadb.sh" 4 seconds ago Up 2 seconds 0.0.0.0:3306->3306/tcp wonderful_hellman
옵션 | 설명 |
-d | 컨테이너를 백그라운드에서 실행 |
-I, -t | 컨테이너를 종료하지 않은 채로 터미널의 입력을 계속해서 컨테이너로 전달하기 위해 사용 |
--name | 컨테이너에 이름을 부여하는 옵션 |
-e | 컨테이너의 환경변수를 설정하기 위해 사용, e옵션을 사용하면 dockerfile env 설정도 덮어씌움 |
-p | 호스트와 컨테이너 간의 포트 설정을 위해 사용 |
-v | 호스트와 컨테이너 간의 불륨 설정을 위해 사용 |
-w | Dockerfile의 WORKDIR 설정을 덮어쓰기 위해 사용 |
--entryponit | Dockerfile의 ENTRYPOINT 설정을 덮어쓰기 위해 사용 |
--rm | 컨테이너를 일회성으로 실행할 때 사용, 컨테이너가 종료될때 컨테이너와 관련된 리소스까지 제거 |
bash | 실행할 명령어 |
4. docker ps
■ 실행중인 컨테이너 조회
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e13badf7c55e mar "/bin/bash" 2 days ago Up 2 days 0.0.0.0:23306->3306/tcp mar1
38b52e7f75e4 tomcat_ss "/usr/local/apache-t…" 2 days ago Up 2 days 8009/tcp, 0.0.0.0:8080->8080/tcp tomcat_12
d56902a6ed17 tomcat_ss "/usr/local/apache-t…" 3 days ago Up 2 days 8009/tcp, 0.0.0.0:9090->8080/tcp tomcat_24
■ 전체 컨테이너 조회(실행 중지된 컨테이너 포함)
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e13badf7c55e mar "/bin/bash" 2 days ago Up 2 days 0.0.0.0:23306->3306/tcp mar1
58e4f7bfa186 mar "/bin/bash" 2 days ago Exited (137) 2 days ago mar
83dff914a5e1 mariadb_1 "--datadir /var/lib/…" 2 days ago Created 0.0.0.0:13306->3306/tcp mariadb_12
5f1297e06616 f2d47922acd4 "/bin/sh -c 'cp -r /…" 2 days ago Exited (1) 2 days ago wonderful_mahavira
64d0d1818653 caae5de51418 "/bin/sh -c '/bin/sh…" 2 days ago Exited (1) 2 days ago youthful_hodgkin
345ffc0e45a0 caae5de51418 "/bin/sh -c 'systemc…" 2 days ago Exited (1) 2 days ago brave_lehmann
c5c611c5c56b centos/mariadb "/docker-entrypoint.…" 2 days ago Exited (137) 2 days ago cen_mariadb
38b52e7f75e4 tomcat_ss "/usr/local/apache-t…" 2 days ago Up 2 days 8009/tcp, 0.0.0.0:8080->8080/tcp tomcat_12
d56902a6ed17 tomcat_ss "/usr/local/apache-t…" 3 days ago Up 2 days 8009/tcp, 0.0.0.0:9090->8080/tcp tomcat_24
58d4fe9f23fd test1 "/usr/local/apache-t…" 3 days ago Exited (143) 3 days ago test1
a0eae7082c5d mariadb/server "docker-entrypoint.s…" 4 days ago Exited (0) 2 days ago mariadb
1c3d41ff674a donglsheng/tomcat9_jdk8 "/usr/local/soft/tom…" 4 days ago Exited (143) 4 days ago tomcat9_jdk8
3e1b7be5980b heartu41/oracle19c "/bin/sh -c 'exec $O…" 4 days ago Exited (143) 3 days ago oracle19c
a170b77af68b tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test1
182aa721c98f tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test2
e3dd9e1a76d1 tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test5
1158a6bc4027 tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test4
25c67f628770 tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test3
e6cd880c5b11 centos:7 "/bin/bash" 5 days ago Exited (137) 4 days ago naughty_pasteur
71da09bd0e19 tomcat:latest "catalina.sh run" 5 days ago Exited (143) 3 days ago tomcat-test
[root@localhost ~]#
5. docker start / stop
■ 컨테이너 확인
[root@localhost ~]# docker ps –a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5f1297e06616 f2d47922acd4 "/bin/sh –c 'cp –r /…" 2 days ago Exited (1) 2 days ago wonderful_mahavira
64d0d1818653 caae5de51418 "/bin/sh –c '/bin/sh…" 2 days ago Exited (1) 2 days ago youthful_Hodgkin
345ffc0e45a0 caae5de51418 "/bin/sh –c 'systemc…" 2 days ago Exited (1) 2 days ago brave_lehmann
C5c611c5c56b centos/mariadb "/docker-entrypoint.…" 2 days ago Exited (137) 2 days ago cen_mariadb
A0eae7082c5d mariadb/server "docker-entrypoint.s…" 4 days ago Exited (0) 2 days ago mariadb
1c3d41ff674a donglsheng/tomcat9_jdk8 "/usr/local/soft/tom…" 4 days ago Exited (143) 4 days ago tomcat9_jdk8
3e1b7be5980b heartu41/oracle19c "/bin/sh –c 'exec $O…" 4 days ago Exited (143) 3 days ago oracle19c
A170b77af68b tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test1
182aa721c98f tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test2
E3dd9e1a76d1 tomcat-org/kawf "catalina.sh run" 4 days ago Exited (143) 4 days ago tomcat-test5
■ 컨테이너 시작
[root@localhost ~]# docker start tomcat9_jdk8
tomcat9_jdk8
■ 컨테이너 중지
[root@localhost ~]# docker stop tomcat9_jdk8
tomcat9_jdk8
6. docker rm / rmi
■ 컨테이너 삭제
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e13badf7c55e mar "/bin/bash" 2 days ago Up 2 days 0.0.0.0:23306->3306/tcp mar1
38b52e7f75e4 tomcat_ss "/usr/local/apache-t…" 2 days ago Up 2 days 8009/tcp, 0.0.0.0:8080->8080/tcp tomcat_12
d56902a6ed17 tomcat_ss "/usr/local/apache-t…" 3 days ago Up 2 days 8009/tcp, 0.0.0.0:9090->8080/tcp tomcat_24
[root@localhost ~]# docker rm e13badf7c55e(컨테이너ID)
[root@localhost ~]#
■ 모든 컨테이너 삭제
[root@localhost ~]# docker rm $(docker ps -a -q)
■ 이미지 삭제
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb_1 latest 85db314b7784 2 days ago 835MB
mar latest 0a3ea032258e 2 days ago 719MB
mariadb_ss latest 69e8d0775c90 2 days ago 400MB
[root@localhost ~]# docker rmi 0a3ea032258e(이미지ID)
[root@localhost ~]#
■ 모든 이미지 삭제
[root@localhost ~]# docker rmi $(docker images -q)
[root@localhost ~]#
7. docker inspect
■ 컨테이너 정보 확인(IP 정보 등)
[root@localhost ~]# docker inspect cea05e370acc(컨테이너ID)
"SandboxKey": "/var/run/docker/netns/e24025b0e23f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "350083c6090a50c98a66f16e02ec0253df5b3c0218d6e702ab9b2fc4fe686b97",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:04",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "a6dab568ed587e9abbc9415fe2f9c3647a0e7c56c1bf421adb0b17d297b7d5f9",
"EndpointID": "350083c6090a50c98a66f16e02ec0253df5b3c0218d6e702ab9b2fc4fe686b97",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:04",
"DriverOpts": null
}
[root@localhost ~]#
8. docker commit
■ 컨테이너 현재 상태 이미지 만들기
1. 현재 컨테이너 목록 확인
[root@localhost ~]# docker ps –a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cea05e370acc mar2 "/root/mariadb.sh" 16 hours ago Exited (137) 2 minutes ago mar2
2. 이미지 저장
[root@localhost ~]# docker commit -p cea05e370acc build_mar2
sha256:9602aca6bb11d62422ebf7d3a2089fbc7a35cdbbb1cf8c71f32c8853194cc285
3. 저장된 이미지 확인
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
build_mar2 latest 9602aca6bb11 13 seconds ago 847MB
mar2 latest 1f00514a3a20 16 hours ago 719MB
9. docker push
■ 이미지를 docker hub 에 업로드
1. 기존 이미지에 tag를 부여하여 업로드 준비
[root@localhost ~]# docker tag build_mar2:latest hiper123/build_mar2:0.1
2. 이미지 확인
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hiper123/build_mar2 0.1 9602aca6bb11 6 hours ago 847MB
3. Docker hub에 업로드
[root@localhost ~]# docker push hiper123/build_mar2:0.1
The push refers to repository [docker.io/hiper123/build_mar2]
9516b3787d9d: Pushed
7c2019fd16f5: Pushed
76c5af19d289: Pushed
c519e7e688f8: Pushed
cec7601adc74: Pushed
4e21910a7f5c: Pushed
174f56854903: Pushed
0.1: digest: sha256:a0a745faf6baace275259fef2bccba89574174e32d8957b8741a4eba4ac8c553 size: 1780
10. docker save / load
■ 이미지 백업(save)
1. 이미지 조회
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
build_mar2 latest 9602aca6bb11 13 seconds ago 847MB
2. 이미지 백업
[root@localhost ~]# docker save -o build_mar2.tar build_mar2
3. OS상에서 이미지 조회
[root@localhost ~]# ls build_mar2.tar
build_mar2.tar
■ 이미지 복원(load)
1. 현재 이미지 삭제
[root@localhost ~]# docker rmi build_mar2
Untagged: build_mar2:latest
Deleted: sha256:9602aca6bb11d62422ebf7d3a2089fbc7a35cdbbb1cf8c71f32c8853194cc285
2. 이미지 조회(삭제 확인)
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
3. 복원하기
[root@localhost ~]# docker load < build_mar2.tar
9516b3787d9d: Loading layer [==================================================>] 128.7MB/128.7MB
Loaded image: build_mar2:latest
4. 이미지 추가 확인
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
build_mar2 latest 9602aca6bb11 6 minutes ago 847MB
11. docker exec
■ 실행된 컨테이너에 접속
- exec 명령을 통한 실행중인 컨테이너에 접속 가능
1. 실행중인 컨테이너 확인
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b20430bb3c3c build_mar2 "/root/mariadb.sh" 34 minutes ago Up 33 minutes 0.0.0.0:3306->3306/tcp wonderful_hellman
2. 컨테이너 접속명령
[root@localhost ~]# docker exec -i -t b20430bb3c3c /bin/bash
[root@b20430bb3c3c /]#
3. 컨테이너 접속확인
[root@b20430bb3c3c /]# cat /etc/*-release
CentOS Linux release 7.9.2009 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)
12. dockerfile 명령어
명령어 | 설명 |
FROM | 생성할 이미지의 베이스가 될 이미지 From 명령어는 Dockerfile을 작성할 때 반드시 한 번 이상 입력해야 하며, 이미지가 docker에 없다면 자동으로 pull 한다 |
Maintainer | 이미지를 생성한 개발자의 정보. 일반적으로 메일 정보를 작성한다 |
LABEL | 메타데이터는 키 : 값 형태로 저장되며, 여러 개의 메타데이터가 저장될 수 있다 |
RUN | 이미지를 만들기 위해 컨테이너 내부에서 명령어를 실행한다 |
ADD,COPY | 파일을 이미지에 추가합니다. 파일은 Dockerfile이 위치한 디렉터리인 컨텍스트에서 가져온다 ADD와 COPY의 차이점은 파일을 추가한다는 베이스는 동일하지만, ADD는 URL 및 .tar 파일의 추가가 가능하다 |
WORKDIR | 명령어를 실행할 디렉터리 지정한다 |
EXPOSE | 빌드로 생성된 이미지에서 노출할 포트를 설정한다 이미지에 노출됐다는 것은 호스트의 포트와 반드시 바인딩 되었음을 의미하는 것이 아니며, 이 포트를 호스트에서 사용할 수 있음을 의미한다 |
CMD | 컨테이너가 시작될 때마다 실행할 명령어를 설정하며, Dockerfile에서 한 번 만 사용할 수 있다 |
ENTRYPOINT | entrypoint는 cmd와 동일하게 컨테이너가 시작될 때 수행할 명령을 지정한다는 점에서 같다 그러나 entrypoint는 커맨드를 인자로 받아 스크립트로 수행할 수 있다는 점에서 다르다 |
ENV | Dockerfile에서 환경변수를 지정한다. 이 환경 변수는 Dockerfile 뿐 아니라 이미지에도 저장되므로 빌드 된 이미지로 컨테이너를 생성하면 내부에서 사용할 수 있다 |
ARG | build 명령어를 실행할 때 추가로 입력을 받아 Dockerfile 내에서 사용될 변수의 값을 설정한다 |
USER | User로 컨테이너 내에서 사용될 사용자 계정이나 uid를 설정한다 |
ONBUILD | 빌드 된 이미지를 기반으로 하는 다른 이미지가 Dockerfile로 생성될 때 실행할 명령어를 추가한다 |
STOPSIGNAL | 컨테이너가 정지될 때 사용될 시스템 콜의 종류를 지정한다. default는 SIGTERM으로 설정된다 |
HEALTHCHECK | health check는 이미지로부터 생성된 컨테이너에서 동작하는 애플리케이션의 상태를 체크하도록 설정한다 애플리케이션의 프로세스는 종료되지 않았으나, 애플리케이션이 동작하지 않을 때 사용된다 |
SHELL | 기본 Shell을 변경할 수 있다 |
'도커(Docker)' 카테고리의 다른 글
컨테이너 가상화(Docker 설치/리눅스/centos) (0) | 2021.06.21 |
---|
댓글