0708-Docker

hyejin·2022년 7월 8일
0

Docker

  • 하이퍼바이저
  • 운영체제 수준 가상화
  • 하드웨어 위에 호스트 os가 있으면 타입2

  • 컨테이너에는 os가 없는이유? 호스트 os에 존재하기 때문에
  • 가볍고 빠르다

도커실습

  • centos7.ova 가져오기

  • 이름 변경

  • mobaxterm으로 접속

--- 센토스 도커 설치(Docker CE; Community Edition 무료 오픈 소스, EE; Enterprise Edition 유료, 보안 관련 서비스 제공)

[root@localhost ~]# curl -fsSL https://get.docker.com/ | sh
[root@localhost ~]# yum -y install bash-completion wget unzip net-tools mysql telnet rdate
[root@localhost ~]# rdate -s time.bora.net && clock -w
[root@localhost ~]# curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  114k  100  114k    0     0   292k      0 --:--:-- --:--:-- --:--:--  292k
[root@localhost ~]# systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker --version
Docker version 20.10.17, build 100c701

--> 도커 엔진 or 도커 호스트

--- 도커 기본 명령어

[root@localhost ~]# docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@localhost ~]# docker image pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b85a868b505f: Pull complete
f4407ba1f103: Pull complete
4a7307612456: Pull complete
935cecace2a0: Pull complete
8f46223e4234: Pull complete
fe0ef4c895f5: Pull complete
Digest: sha256:10f14ffa93f8dedf1057897b745e5ac72ac5655c299dade0aa434c71557697ea
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    55f4b40fe486   2 weeks ago   142MB
[root@localhost ~]# docker image inspector nginx
[root@localhost ~]# docker image inspect --format="{{ .Os}}" nginx
linux
[root@localhost ~]# docker image inspect --format="{{ .DockerVersion}}" nginx
20.10.12  // 검색
[root@localhost ~]# docker image inspect nginx | grep LastTagTime
            "LastTagTime": "0001-01-01T00:00:00Z" // 검색방법
[root@localhost ~]# docker container create -p 80:80 --name webserver nginx
4d83a6a7654379f6b5df601ee47a89e521e01bcbc0d54a0a8644c72cef67d122
[root@localhost ~]# docker container start webserver
webserver
[root@localhost ~]# docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS          PORTS                               NAMES
4d83a6a76543   nginx     "/docker-entrypoint.…"   8 minutes ago   Up 15 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   webserver
  • 192.168.1.85로 접속
[root@localhost ~]# docker container run -p 80:80 --name webserver nginx # foreground 실행
[root@localhost ~]# docker container run -p 80:80 --name webserver nginx # foreground 실행
8c5791e842a037985cd75efce2bc0f8d040b9984954ac294979bba57364ded98
[root@localhost ~]# docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                               NAMES
8c5791e842a0   nginx     "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   webserver
  • 컨테이너 이름 충돌시 이름에 2를 붙이면 해결
  • 포트 충돌시 포트 번호 변경해도 해결 X -> create 상태로 만들어짐
[root@localhost ~]# docker container run --name test_cal centos /bin/cal
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
      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 container run --name test_cal centos /bin/cal
[root@localhost ~]# docker container run -it --name test_bash centos /bin/bash
// -it는 별표 5개
[root@localhost ~]# docker container run -d --name test_ping centos /bin/ping localhost
[root@localhost ~]# docker container logs -t test_ping
[root@localhost ~]# docker container run -d -p 8080:80 --name test_port nginx
[root@localhost ~]# docker container stats nginx
//-d 는 backgroud 실행
[root@localhost ~]# docker container run -d -p 8181:80 --cpus 1 --memory=256m --name test_resource nginx
[root@localhost ~]# docker container run -d -p 8282:80 --cpus 1 --memory=256m -v /tmp:/usr/share/nginx/html --name volume-container nginx 

[root@localhost ~]# docker container ls -a -f name=test_webserver
[root@localhost ~]# docker container ls -a -f exited=0
[root@localhost ~]# docker container ls -a --format "table {{.Names}}\t{{.Status}}"
[root@localhost ~]# docker container attach test_bash

0개의 댓글

관련 채용 정보