0711-Docker

hyejin·2022년 7월 11일
0

Docker

삭제 명령어

# docker ps //줄이기
# docker rm -f $(docker ps -a -q)
767a73f75a22
9f2dbc13a56c
31689445afda
f1e5ee5f096e
9e5983a0b395
79eca374d2ac
2c081d9a590a
be6e203d2e6c
55d6d3872fd0
8c5791e842a0
# docker image rm nginx
Untagged: nginx:latest
Untagged: nginx@sha256:10f14ffa93f8dedf1057897b745e5ac72ac5655c299dade0aa434c71557697ea
# docker rmi centos:latest  //rmi = image rm, image name으로 삭제
Untagged: centos:latest
Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59
# docker rmi 8683a143c9c7 //image ID 로 삭제
# docker rmi $(docker images -q) //image 전부 삭제

run 명령어

[root@localhost ~]# docker run --name test_cal centos:7 /bin/cal
Unable to find image 'centos:7' locally
7: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:c73f515d06b0fa07bb18d8202035e739a494ce760aa73129f60f4bf2bd22b407
Status: Downloaded newer image for centos:7
      July 2022
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE      COMMAND      CREATED          STATUS                      PORTS     NAMES
8dc735bdb995   centos:7   "/bin/cal"   51 seconds ago   Exited (0) 44 seconds ago             test_cal
[root@localhost ~]# docker run --name test_cal1 --rm  centos:7 /bin/cal
      July 2022
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
# docker run -it --name test_bash1 centos:7 /bin/bash// -i는 표준입력, 상호작용을 위함
[root@localhost tmp]# docker ps -a --format "table {{.Command}}\t{{.Ports}}"
COMMAND                  PORTS
"/docker-entrypoint.…"   0.0.0.0:8282->80/tcp, :::8282->80/tcp
"/docker-entrypoint.…"   0.0.0.0:8181->80/tcp, :::8181->80/tcp
"/docker-entrypoint.…"   0.0.0.0:8080->80/tcp, :::8080->80/tcp
"/bin/ping localhost"
"/bin/bash"
"/bin/bash"
"/bin/cal"
  • filter
[root@localhost tmp]# docker ps -a -f name=test_bash
CONTAINER ID   IMAGE      COMMAND       CREATED          STATUS                      PORTS     NAMES
933da1e70f81   centos:7   "/bin/bash"   43 minutes ago   Exited (0) 43 minutes ago             test_bash1
bad808219727   centos:7   "/bin/bash"   49 minutes ago   Up 49 minutes                         test_bash
  • exec
[root@localhost tmp]# docker exec -it test_bash /bin/bash
[root@bad808219727 /]#
  • rename
[root@localhost tmp]# docker rename test_port webserver
[root@localhost tmp]# docker ps -a -f name=webserver
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
8e13391020c0   nginx     "/docker-entrypoint.…"   43 minutes ago   Up 43 minutes   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver
  • copy
[root@localhost tmp]# cd ~
[root@localhost ~]# ls
[root@localhost ~]# docker cp webserver:/usr/share/nginx/html/index.html /root/index.html
[root@localhost ~]# ls
index.html
[root@localhost ~]# docker cp ./index.html webserver:/usr/share/nginx/html/index.html
[root@localhost ~]# docker diff webserver
C /usr
C /usr/share
C /usr/share/nginx
C /usr/share/nginx/html
C /usr/share/nginx/html/index.html
C /run
A /run/nginx.pid
C /etc
C /etc/nginx
C /etc/nginx/conf.d
C /etc/nginx/conf.d/default.conf
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/client_temp
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
A /var/cache/nginx/scgi_temp
A /var/cache/nginx/uwsgi_temp

  • copy
[root@localhost ~]# ls
food.tar  index.html
[root@localhost ~]# mkdir html
[root@localhost ~]# ls
food.tar  html  index.html
[root@localhost ~]# tar -xvf food.tar -C html
[root@localhost ~]# docker cp ./html webserver:/usr/share/nginx

  • commit2
[root@localhost ~]# docker commit -a "hyejin<test@example.com>" -m "FOOD" webserver test_commit:v1.0
sha256:234da1de60e3c768c32326bcbd1d61f6db6c7f5f6689c34790f8fac2358ecf57
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
test_commit   v1.0      234da1de60e3   27 seconds ago   170MB
nginx         latest    55f4b40fe486   2 weeks ago      142MB
centos        7         eeb6ee3f44bd   9 months ago     204MB
  • save (이미지로 저장)
[root@localhost ~]# docker save -o test_commit.tar test_commit:v1.0
[root@localhost ~]# ls
food.tar  html  index.html  test_commit.tar
[root@localhost ~]# ls -al
total 198532
dr-xr-x---.  5 root root       205 Jul 11 12:04 .
dr-xr-xr-x. 17 root root       244 Jul  8 10:22 ..
-rw-------.  1 root root      5440 Jul 11 10:33 .bash_history
-rw-r--r--.  1 root root        18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root       176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root       176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root       100 Dec 29  2013 .cshrc
-rw-r--r--   1 root root  28642816 Jul 11 11:41 food.tar
drwxr-xr-x   4 root root        53 Jul 11 11:41 html
-rw-r--r--   1 root root       616 Jul 11 11:34 index.html
drwxr-----   3 root root        19 Jul  8 10:30 .pki
drwx------   2 root root        25 Jul  8 16:39 .ssh
-rw-r--r--.  1 root root       129 Dec 29  2013 .tcshrc
-rw-------   1 root root 174617600 Jul 11 12:04 test_commit.tar

192.168.1.85 접속 후

# ip a

veth66c3c92@if12 // @뒤는 컨테이너
veth2fc7070@if14
vethe0f4a1e@if16

[root@localhost ~]# docker exec -it test_bash /bin/bash
[root@bad808219727 /]# yum install -y net-tools
[root@bad808219727 /]# yum install -y iproute

  • 동그라미가 컨테이너 LAN카드 번호
  • 밑줄이 컨테이너 실제 이름
  • 서로 링크되어 있음
  • 도커 네트워크
[root@localhost ~]# docker network create -d bridge --subnet 192.168.123.0/24 --ip-range 192.168.123.128/25 test_bridge
9e2243373f6aa27e5ca0030073fc1d8b4a8cae44fed8287c5cc6695dc486f8a2
[root@localhost ~]# docker run -d -p 8383:80 --name webserver2 --network test_bridge nginx
1b426c38996652cbb6092784e67148a522f8a6da52c30bd16a83655b7b6945d3

워드프레스

코드를 입력하세요

  • tag
[root@localhost ~]# docker tag test_commit:v1.0 seozzang3/test_commit:v1.0
[root@localhost ~]# docker images
REPOSITORY              TAG       IMAGE ID       CREATED        SIZE
test_commit             v1.0      234da1de60e3   4 hours ago    170MB
seozzang3/test_commit   v1.0      234da1de60e3   4 hours ago    170MB
nginx                   latest    55f4b40fe486   2 weeks ago    142MB
mariadb                 latest    ea81af801379   4 weeks ago    383MB
centos                  7         eeb6ee3f44bd   9 months ago   204MB

ubuntu-node2로 접속

--- 우분투 도커 설치

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
$ sudo apt update
$ sudo apt-cache policy docker-ce
$ sudo apt install docker-ce
root@ununtu-node02:~# docker run -d -p 80:80 --name webserver seozzang3/test_commit:v1.0
Unable to find image 'seozzang3/test_commit:v1.0' locally
v1.0: Pulling from seozzang3/test_commit
b85a868b505f: Pull complete
f4407ba1f103: Pull complete
4a7307612456: Pull complete
935cecace2a0: Pull complete
8f46223e4234: Pull complete
fe0ef4c895f5: Pull complete
8cef7d5c61eb: Pull complete
Digest: sha256:09a5cdfeffb2f2cef04df8971ad9d1da7c5d83371b3027f732d2ef0eb3b42c9c
Status: Downloaded newer image for seozzang3/test_commit:v1.0
dec7737a6eb331346c43714c7e710a6a452be29710e2b612bd5ee29fb9b4432f

--- 도커 파일 이해

  • docker 에서 실행
[root@localhost ~]# mkdir test && cd $_
[root@localhost ~]# vi Dockerfile
# vi Dockerfile
FROM ubuntu:18.04
MAINTAINER johnlee
LABEL "name"="webserver"
ENV aloha=date
ENV path=/var/www/html
RUN sed -i 's/archive.ubuntu.com/ftp.daumkakao.com/g' /etc/apt/sources.list
RUN apt-get update                 // 설치
RUN apt-get install apache2 -y
COPY nihao /var/www/html/nihao    //파일 복사
COPY hello.html $path
ADD aws.tar /var/www/html        //파일 추가
WORKDIR /var/www/html
RUN echo ohayo >> ohayo.html
VOLUME /var/www/html
EXPOSE 80
ENTRYPOINT ["apachectl"]
CMD ["-D", "FOREGROUND"]

0개의 댓글

관련 채용 정보