28.12.16

DOCKER Notes

VIRTUAL MACHINE VS CONTAINERS

Virtualized Machines             Containers
- mixed operating systems      - efficient
- more flexible                        - less operating system maintenance
- mature technology                - quick deployment
                                                - not yet flexible

Virtual Machines                 Containers

[ Applications ]                    [ Applications ] [Applications]
[Operating Sys]                    [ Applications ] [Applications]
-------------------                         [  Operating Systems  ]
  [Hypervisor]
-------------------
[Operating Sys]

DOCKER WORKS...

3 Steps of Docking (Docker Containers)

[1] Docker File -> creates [2] Images -> creates [3] Containers
- Dependencies
- PHP
- NGINX / Apache
- Java
- Debian / Gentoo

Docker Daemon to faciliates the 3 steps


- apt-cache search docker
- wget -q0- https://docker.com/ | sh
- sudo docker run -d [operating system]  [applications]
  sudo docker run -d gentoo /bin/bash [application]
- sudo docker ps -a
- sudo docker logs [port number]
- sudo docker start [name]
- sudo docker stop [name]
- sudo docker images
- sudo docker search [application]
   sudo docker search php
- sudo docker pull [application]
   sudo docker pull php


Docker Hub - Online depository of Docker images

Containers and Images

- Images that can host java, apache, php - requires to run applications
- Containers consolidates the applications
- Images are just copied in the containers
- Updating a container, we delete the application and start a fresh copy of the application
- Dont update the application in the container

- sudo docker ps
- sudo docker ps -a
- sudo docker images
- sudo docker pull
- sudo docker rmi
- sudo docker rm

NETWORKING DOCKER

Virtual Interfaces
Bridged Networking
Configuring IP Address

etho: 192.168.1.201
docker0: 172.16.10.1
veXXXXXX: Bridge - where XXXXX is the MAC ADDRESS

Container is assigned via IP Address that is accessible thru out the network

- sudo docker run - d XXXXX/yyyyyy
- sudo docker inspect container | grep IP


publishing a docker to port 8080 (with random port in the container)
- sdo docker run -d -p 8080 boyformat/jabaman

publishing a docker to port 8080 via 0529
- sudo docker run -d -p 8080:0529 boyformat/jabaman

publishing a docker to port 8080 via 0529 / 8080 via 0329
- sudo docker run -d -p 8080:0529 -p 8080:0329 boyformat/jabaman

DATA STRUCTURES (PERSISTENT AND SHARED)

- Host file system can be network mounted
- Pointing the directory to /etc/fstab

- sudo docker run -d nginx
- sudo docker ps
- sudo docker inspert docker_name | grep IP

check via a web browser on the IP Address to be generated

- mkdir  web
- cd web
- vi index.html

- sudo docker run - d -v /home/jabaman/web:/usr/share/nginx/hmtl nginx
- sudo docker ps

Mounting a docker file
Docker ... -v [local directory]:[container directory]

Modifying Containers and Images

- sudo docker exec -i -t my_applicationtemp bash
- cd user/share/html/nginx/html  
- less index.html
- rm index.html
- cat index.html
- sudo docker commit my_applicationtemp my_application
- sudo docker images
- sudo docker ps
- sudo docker run -d my_application
- sudo docker ps
- sudo docker inspect | grep IP

Creating Image

Base image - includes applications (docker file) 

Sample:
Maintainer Boyformat
Copy counter.sh /usr/local/bin/counter.sh
RUN chmod + x /usr/local/bin/counter.sh
CMD ["/usr/local/bin/counter.sh"]






0 comments: