• 설치, 실행 과정으로 빠르게 훑어보는 docker 서비스의 이해
  • ‘생활코딩 Docker 입구 수업’ 내용을 정리 (Update: Aug 20, 2021)

1. Docker 설치 파일

; Docker (Desktop) for MAC, Windows, Linux
Get Docker

2. 설치 및 확인

  • docker (desktop) 설치, 실행
  • docker images 실행, 확인

3. Pull & Run

[ docker hub ] pull [ image ] run [ container ]
(operation) (operation)

3-1. 도커 이미지 pull

; docker image 생성
; httpd image 적용의 예

~ docker pull httpd
~ docker images

$ docker pull [OPTIONS] NAME[:TAG|@DIGEST]
$ docker images [OPTIONS] [REPOSITORY[:TAG]]
https://docs.docker.com/engine/reference/commandline/pull/ https://docs.docker.com/engine/reference/commandline/images/

3-2. 도커 이미지 run, stop, start, delete

; docker image 에서 container 생성, 실행

~ docker run httpd
~ docker run --name web2 httpd

$ docker run [OPTIONS] IMAGE [COMMAND] [ARG…]
https://docs.docker.com/engine/reference/commandline/run/

; 생성 및 실행중인 container 확인

~ docker ps
~ docker ps -a		              #모든 container 확인

$ docker ps [OPTIONS]
https://docs.docker.com/engine/reference/commandline/ps/

; container 중지, 실행, 로그 확인

~ docker stop web2
~ docker start web2
~ docker logs -f web2

$ docker stop [OPTIONS] CONTAINER [CONTAINER…]
$ docker start [OPTIONS] CONTAINER [CONTAINER…]
$ docker logs [OPTIONS] CONTAINER
https://docs.docker.com/engine/reference/commandline/start/
https://docs.docker.com/engine/reference/commandline/stop/
https://docs.docker.com/engine/reference/commandline/logs/

; container 삭제

~ $ docker rm web2			      #stop 상태의 web2 container 삭제
~ $ docker rm --force web2

docker rm [OPTIONS] CONTAINER [CONTAINER…]
https://docs.docker.com/engine/reference/commandline/rm/

; image 삭제
; httpd image 삭제의 예

~ $ docker rmi httpd

$ docker rmi [OPTIONS] IMAGE [IMAGE…]
https://docs.docker.com/engine/reference/commandline/rmi/

4. network

; docker host port 와 container port mapping

20210818_quick_install_run_docker_img01

~ $ docker run -p 8000:80 httpd
~ $ docker run --name web3 -p 8080:80 httpd

5. container filesystem

; docker host의 filesystem을 container filesystem으로 container 생성, 실행

20210818_quick_install_run_docker_img02

~ docker run -p 8080:80 -v ~/Desktop/htdocs:/usr/local/apache2/htdocs/ httpd 

~ "docker run -p 8888:80 -v C:\Users\USER1\Desktop\htdocs\:/usr/local/apache2/htdocs/ httpd"

hub.docker.com - httpd - How to use this image

6. container CLI

; docker container 내 명령 실행, shell 열어서 연속 작업하기

~ docker exec web3 pwd
~ docker exec -it web3 /bin/sh		#web3 container에서 shell 실행
~ docker exec -it web3 /bin/bash	    # -it 옵션으로 container cli 연결 유지
# pwd
# apt update
# apt install vim
# vi /usr/local/apache2/htdocs/index.html
# exit

이미지 및 참고 글