Install Docker (실습용 VM 의 경우)

아래 링크를 참고해서 Docker CE 를 설치합니다.

https://docs.docker.com/install/

Install Docker (Ubuntu)

https://docs.docker.com/install/linux/docker-ce/ubuntu/

Ubuntu 16.04 환경인 실습 VM 에서 kubectl cli 를 설치하는 script 입니다.

  1. sudo apt update
  2. sudo apt install -y apt-transport-https ca-certificates software-properties-common curl
  3. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. sudo apt update
  6. sudo apt install -y docker-ce
  7. id
  8. sudo usermod -a -G docker ibmcloud
  9. sudo systemctl restart ttyd
    1. 접속이 끊기면 새로고침하여 재접속합니다.

Docker 101

  1. id
  2. docker
  3. docker version

Your First Linux Containers

https://training.play-with-docker.com/ops-s1-hello/

  1. docker run hello-world
  2. docker container run hello-world hello-world
  3. docker pull alpine
  4. docker image pull alpine
  5. docker images
  6. docker image ls
  7. docker container run alpine ls -l Docker run details
  8. docker container run alpine echo "hello from alpine"
  9. docker container run alpine /bin/sh
  10. docker container run -it alpine /bin/sh
    1. ls -l
    2. uname -a
    3. ls /bin/
    4. ls /usr/bin/
    5. df -h
    6. exit
  11. docker ps
  12. docker container ls
  13. docker container ls -a Docker Container Instances
  14. docker container run -it --name myalpine alpine /bin/ash
    1. echo "hello world" > hello.txt
    2. ls
    3. cat hello.txt
    4. exit
  15. docker container ls -a Docker Container Isolation
  16. docker container start <container ID>
  17. docker container ls
  18. docker container exec <container ID> ls docker container exec
  19. docker container exec -it <container ID> sh
    1. ls
    2. cat hello.txt
    3. exit
  20. ps auxf
  21. docker container ls -a
  22. docker container rm <container ID>
  23. docker stop <container ID>
  24. docker container rm <container ID>
  25. docker container rm <container name>
  26. docker container ls -a
  27. docker image ls
  28. docker image ls -q
  29. docker image ls -q |xargs docker image rm

Docker port and volume

  1. docker container run -d --name mynginx nginx
  2. docker container ls
  3. docker container exec mynginx hostname -I
  4. ifconfig docker0
  5. curl http://<container IP
  6. ps auxf
  7. docker container run -d --name mynginx2 -p 8080:80 nginx:alpine
  8. docker container ls
  9. ifconfig eth1
  10. http://아이피:8080 페이지 확인
  11. cd ~/workspace
  12. docker container cp mynginx2:/etc/nginx/conf.d/default.conf .
  13. cat default.conf
  14. docker container exec mynginx2 cat /usr/share/nginx/html/index.html
  15. echo "hello world!" > index.html
  16. cat index.html
  17. docker container cp index.html mynginx2:/usr/share/nginx/html/index.html
  18. docker container exec mynginx2 cat /usr/share/nginx/html/index.html
  19. http://아이피:8080 페이지 확인
  20. docker container run -d --name mynginx3 -p 8083:80 -v /home/ibmcloud/workspace:/usr/share/nginx/html nginx:alpine
  21. http://아이피:8083 페이지 확인
  22. echo "hello??" > index.html
  23. http://아이피:8083 페이지 확인
  24. docker container ls
  25. docker container stop $(docker container ls -aq)
  26. docker container ls
  27. docker container ls -a
  28. docker system prune
  29. docker container ls -a
  30. docker image ls
  31. docker image prune -a
  32. docker image ls

Build Docker image

  1. cd ~/workspace
  2. git clone https://github.com/IBM/container-service-getting-started-wt
  3. cd container-service-getting-started-wt/Lab\ 1
  4. cat package.json
  5. cat app.js
  6. cat Dockerfile
  7. Dockerfile 수정: COPY app.js . 을 마지막줄로 옮깁니다.
  8. docker image build -t hello-world:1 .
  9. docker image ls
  10. docker image inspect hello-world:1
  11. docker container run -d -p 8080:8080 --name hello-world-a hello-world:1
  12. docker container ls
  13. curl http://localhost:8080
  14. docker container logs hello-world-a
  15. docker container run -d -p 8081:8080 --name hello-world-b hello-world:1
  16. curl http://localhost:8081
  17. app.js 수정: 7번째 줄 끝 clustercontainer 로 바꿉니다.
  18. docker image build -t hello-world:2 .
  19. docker container run -d -p 8082:8080 --name hello-world-c hello-world:2
  20. curl http://localhost:8082
  21. docker container stop hello-world-a hello-world-b
  22. ps auxf |grep app.js |grep node
  23. docker container ls
  24. sudo kill <PID>
  25. docker container ls
  26. docker container ls -a
  27. docker container logs hello-world-c
  28. docker container logs hello-world-b
  29. docker system prune