# <h1>Intro to Docker</h1> --- layout: false .left-column[ # Prep ] .right-column[ ### Download the following: ###- [Docker](https://download.docker.com/mac/stable/Docker.dmg) ###- [MySQLWorkbench](https://dev.mysql.com/downloads/workbench/) ###- [Resource files](http://hashbytes.com/) ] --- # What is Docker? Docker is a platform for developers to build, run, and share applications with containers. ??? Docker is a platform for developers and sysadmins to build, run, and share applications with containers. The use of containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is. Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. --- # Images and containers You build images, you create/run/start containers ??? Fundamentally, a container is nothing but a running process, with some added encapsulation features applied to it in order to keep it isolated from the host and from other containers. One of the most important aspects of container isolation is that each container interacts with its own private filesystem; this filesystem is provided by a Docker image. An image includes everything needed to run an application - the code or binary, runtimes, dependencies, and any other filesystem objects required. Container is the actual instantiation of the image just like how an object is an instantiation or an instance of a class. A Docker image packs up the application and environment required by the application to run, and a container is a running instance of the image --- # Docker vs. Virtual Machines? <img src="images/Blog.-Are-containers-..VM-Image-1.png" alt="Drawing" style="width: 600px;"/> ??? Docker is a platform for developers and sysadmins to build, run, and share applications with containers. The use of containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is. --- ## My Patent - 2002 Workload balancing using dynamically allocated virtual servers http://www.freepatentsonline.com/7080378.html <img src="images/VM Patent.jpg" alt="Drawing" style="height: 400px;"/> --- <img src="images/VM Patent.jpg" alt="Drawing" style="height: 600px;"/> --- # Images and containers You build images, you create/run/start containers ??? Fundamentally, a container is nothing but a running process, with some added encapsulation features applied to it in order to keep it isolated from the host and from other containers. One of the most important aspects of container isolation is that each container interacts with its own private filesystem; this filesystem is provided by a Docker image. An image includes everything needed to run an application - the code or binary, runtimes, dependencies, and any other filesystem objects required. Container is the actual instantiation of the image just like how an object is an instantiation or an instance of a class. A Docker image packs up the application and environment required by the application to run, and a container is a running instance of the image --- # Check docker -v --- # MySQLWorkbench /Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench --help open MySQLWorkbench.app --- # Hello world docker run hello-world --- # Ubuntu docker run -it ubuntu bash docker run -it --name my-ubuntu ubuntu bash exit --- # Dockerfile --- layout: false .left-column[ ## Next Sections ] .right-column[ The upcoming sections will discuss the following subjects: - Listing images, listing containers, etc. - Clean up - removing images and containers - Running a container in interactive mode ] --- ## Useful commands - Containers ### docker ps -a ### docker stop $(docker ps -aq) && docker rm $(docker ps -aq) --- ## Useful commands - Images ### docker images ### docker rmi $(docker images -q) --- # Building a MySQL image ## Build a custom MySQL image ### docker rmi $(docker images -q) --- # Official MySQL image ## [Official MySQL image](https://hub.docker.com/_/mysql) ### docker rmi $(docker images -q) --- # MySQL Dockerfile ```dockerfile # Derived from official mysql image (our base image) FROM mysql # Add a database ENV MYSQL_DATABASE HR # Add the content of the sql-scripts/ directory to your image # All scripts in docker-entrypoint-initdb.d/ are automatically # executed during container startup COPY ./sql-scripts/HR/ /docker-entrypoint-initdb.d/ ``` --- # MySQL Dockerfile cd $ROOT docker rmi $(docker images -q my-mysql-image) docker build -t my-mysql-image . docker images docker run -d -p 3366:3306 --name my-mysql -e MYSQL_ROOT_PASSWORD=supersecret my-mysql-image --- # MySQL docker exec -it my-mysql bash mysql -uroot -p supersecret show databases; use HR; show tables; show columns from employees; select * from employees; quit exit --- # phpMyAdmin docker run --name my-own-phpmyadmin -d --link my-mysql:db -p 8081:80 phpmyadmin/phpmyadmin http://localhost:8081/