Introduction to Docker by Alex Collins
Same same, but different.
Want to start MySQL? Easy - just use a container someone else has made first.
"If you can contain it, we can deploy it."
Kill it and start a new one from the image.
Fewer dependency problems.
On the devs machine, on the QA's machine, and in production.
"As a rule of thumb, if you ever read an article citing scientific evidence that doesn’t mention its limitations, the author has not presented the full story."
Many tools for every task, but how do you know you've choosen the best?
Install the Dependencies
brew install boot2docker docker
Interlude #1:
What is Boot2Docker
Start-up Daemon
boot2docker init
boot2docker up
Find An Image
docker search mysql
Start A MySQL Container
docker run -P -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
Find the started container in the Docker process list
docker ps
Interlude #2:
Port-forwarding
VBoxManage controlvm boot2docker-vm natpf1 "3306,tcp,127.0.0.1,3306,,3306"
Test Container
brew install mysql
mysql --protocol TCP -u root -p
create database mydb;
connect mydb;
create table foo(bar int);
Or use an SQL client you like.
Stop Container
docker ps
docker stop ...
Oneliner to stop all containers:
docker stop $(docker ps -q)
Rather than Vagrantfile
, we have Dockerfile
:
FROM centos
ADD somefile.png .
EXPOSE 80
CMD ["echo", "Hello Docker"]
Create new directory with this Dockerfile
:
FROM nginix
Build it:
docker build -t myapp .
Run it:
docker run -P -p 8080:80 myapp
VBoxManage controlvm boot2docker-vm natpf1 "8080,tcp,127.0.0.1,8080,,8080"
Open http://localhost:8080 in your browser to sees your work.
Get an image and save it.
Create index.html
:
I love Docker!
Add to Dockerfile
:
ADD myimage.png /usr/share/nginx/html/
ADD index.html /usr/share/nginx/html/
Kill the running container, rebuild and run again.
docker run -P -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
mysql --protocol TCP -u root -p
create database mydb;
docker stop $(docker ps -q);
docker run -v /var/lib/mysql --name data busybox
docker run -P -p 3306:3306 -volumes-from data -e MYSQL_ROOT_PASSWORD=123456 mysql
mysql --protocol TCP -u root -p
create database mydb;
docker stop $(docker ps -q)