Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Broughttoyou
byHenrykKonsek
Docker
For mere mortals.
hekonsek@gmail.com | @hekonsek
● What is Docker
● Background
● Key concepts + first steps
● Layers
● Publishing images
● Volumes
● Networking
● Good practices
This session
What is Docker
Server for running and managing Linux containers.
What is...
Operating-system-level virtualization.
What are Linux containers?
chroot on steroids + some kernel magic
What are Linux containers?
● slooooooow
● gigantic images
● aggressive resource allocation
● bad API
Why not regular virtualization?
Background
Created by this dude
Solomon Hykes
Based on LXC
Docker team created their own LXC using Go.
Key concepts + first steps
Container is the running image.
Key concepts
● image (immutable, no state)
● container (mutable, has state)
Container is the running image.
Key concepts
Archived filesystem + metadata.
Docker image
No memory snapshots!
Docker image
Like Git, but for containers.
Commands
Install Docker on Ubuntu.
Before you start
$ curl -sSL https://get.docker.com/ | sh
$ service docker start
$ docker version
Let’s run Dockerized shell in new container.
Dockerized shell using base image
$ docker run -it ubuntu /bin/bash
Docker container == pimped Unix process
Start ‘top’ process in Docker. See/kill it from the host.
Docker container == pimped Unix process
$ docker run -it ubuntu /bin/bash
$ top
$ ps aux | grep top
$ sudo kill -9 <TOP_PID>
Let’s run daemon process in the new container.
Daemon process using base image
$ docker run -it ubuntu /usr/bin/top
Let’s run daemon process in the backgronud. Then kill it.
Background daemon process using
base image
$ docker run -d -it ubuntu /usr/bin/top
$ docker ps
$ docker stop <containerId>
$ docker start <containerId>
Tail into the running process.
See background process output
$ docker run -d -it ubuntu /usr/bin/top
$ docker ps
$ docker logs -f <containerId>
Layers
Layers
WAR
Tomcat
JRE
Ubuntu base
Let’s containerize the execution of process.
Dockerized command execution
FROM ubuntu
RUN apt-get update -qqy
RUN apt-get install -qqy cowsay
ENTRYPOINT ["/usr/games/cowsay"]
CMD ["I'm development cow!"]
''
$ docker build -t mycow .
$ docker run -t mycow
$ docker run -t mycow 'I am production cow!'
Copy and display host’s fstab.
Add files to the container
FROM ubuntu
ADD fstab /tmp/copied_fstab
ENTRYPOINT ["cat", "/tmp/copied_fstab"]
$ docker build -t fstaber .
$ docker run -t fstaber
$ cp /etc/fstab fstab
Publishing images
Just like Git repositories :) .
Registries.
Create your DockerHub (http://hub.docker.com) account.
Before we start
Push to the DockerHub with the latest tag.
Push to the DockerHub registry
docker login
docker build -t hekonsek/test:1 .
docker tag -f hekonsek/test:1 hekonsek/test:latest
docker push hekonsek/test
Volumes
How can containers share
the file system?
You can share filesystem between host and containers.
Mounting host filesystem
$ docker run -v /etc:/etc-from-host -it ubuntu /bin/bash
$ ls /etc-from-host
Provided by the database community/vendor.
How can I get database image?
$ docker run -d -p 27017:27017 --name mongodb mongo
$ apt-get install mongodb-clients
$ mongo
]
Mount volume container.
Mounting volumes
docker run -v /data/db --name mongodb_data busybox true
docker run -d --volumes-from mongodb_data -p 27017:27017 --name
mongodb mongo
Browse data from the volume.
Mounting volumes
$ docker run --volumes-from mongodb_data -it ubuntu /bin/bash
$ ls /data/db
Create backup of the MongoDB data.
Backups
$ docker run --volumes-from mongodb_data -v $(pwd):/backup
ubuntu tar cvf /backup/backup.tar /data
Networking
ip a | grep docker
Virtual ethernet bridge
Containers can access Internet. Internet can’t access containers.
Containers are behind of kinda NAT
Docker server can forward ports from containers.
Remember MongoDB?
$ docker run -d -p 27017:27017 --name mongodb mongo
Let the cow count items in collection using linked MongoDB.
How container A can access
the network of container B?
$ docker run --link mongodb:mongodb -it ubuntu /bin/bash
$ apt-get update -qqy
$ apt-get install -qqy mongodb-clients
$ apt-get install -qqy cowsay
$ echo 'db.foo.count()' | mongo mongodb:27017 |
/usr/games/cowsay
Kubernetes for the rescue.
Networking is hard
Good practices
The generic approach to connect to the service from your application.
Connections failover
env:MONGODB_SERVICE_HOST # Kubernetes / Custom
mongodb # linked container
localhost # localhost
The order of the instructions in Dockerfile is important.
Build with the caching in mind
$ docker build ...
Immutable deployment. Use ENV variable to the container.
Build once. Run everywhere.
Docker Maven plugin by Roland ‘Jolokia’ Huß
How can I put a fresh jar into an image?
How can I put a fresh jar into an image?
<image>
<name>${project.artifactId}:${project.version}</name>
<build>
<from>hekonsek/fatjar:0.0.10-SNAPSHOT</from>
<assemblyDescriptorRef>artifact</assemblyDescriptorRef>
<exportDir>/jars</exportDir>
</build>
</image>
mvn docker:buid docker:push
docker rmi $(docker images -q)
Remove images from time to time :)
Thank you!

More Related Content

Docker for mere mortals

  • 3. ● What is Docker ● Background ● Key concepts + first steps ● Layers ● Publishing images ● Volumes ● Networking ● Good practices This session
  • 5. Server for running and managing Linux containers. What is...
  • 7. chroot on steroids + some kernel magic What are Linux containers?
  • 8. ● slooooooow ● gigantic images ● aggressive resource allocation ● bad API Why not regular virtualization?
  • 10. Created by this dude Solomon Hykes
  • 11. Based on LXC Docker team created their own LXC using Go.
  • 12. Key concepts + first steps
  • 13. Container is the running image. Key concepts ● image (immutable, no state) ● container (mutable, has state)
  • 14. Container is the running image. Key concepts
  • 15. Archived filesystem + metadata. Docker image
  • 17. Like Git, but for containers. Commands
  • 18. Install Docker on Ubuntu. Before you start $ curl -sSL https://get.docker.com/ | sh $ service docker start $ docker version
  • 19. Let’s run Dockerized shell in new container. Dockerized shell using base image $ docker run -it ubuntu /bin/bash
  • 20. Docker container == pimped Unix process
  • 21. Start ‘top’ process in Docker. See/kill it from the host. Docker container == pimped Unix process $ docker run -it ubuntu /bin/bash $ top $ ps aux | grep top $ sudo kill -9 <TOP_PID>
  • 22. Let’s run daemon process in the new container. Daemon process using base image $ docker run -it ubuntu /usr/bin/top
  • 23. Let’s run daemon process in the backgronud. Then kill it. Background daemon process using base image $ docker run -d -it ubuntu /usr/bin/top $ docker ps $ docker stop <containerId> $ docker start <containerId>
  • 24. Tail into the running process. See background process output $ docker run -d -it ubuntu /usr/bin/top $ docker ps $ docker logs -f <containerId>
  • 27. Let’s containerize the execution of process. Dockerized command execution FROM ubuntu RUN apt-get update -qqy RUN apt-get install -qqy cowsay ENTRYPOINT ["/usr/games/cowsay"] CMD ["I'm development cow!"] '' $ docker build -t mycow . $ docker run -t mycow $ docker run -t mycow 'I am production cow!'
  • 28. Copy and display host’s fstab. Add files to the container FROM ubuntu ADD fstab /tmp/copied_fstab ENTRYPOINT ["cat", "/tmp/copied_fstab"] $ docker build -t fstaber . $ docker run -t fstaber $ cp /etc/fstab fstab
  • 30. Just like Git repositories :) . Registries.
  • 31. Create your DockerHub (http://hub.docker.com) account. Before we start
  • 32. Push to the DockerHub with the latest tag. Push to the DockerHub registry docker login docker build -t hekonsek/test:1 . docker tag -f hekonsek/test:1 hekonsek/test:latest docker push hekonsek/test
  • 34. How can containers share the file system?
  • 35. You can share filesystem between host and containers. Mounting host filesystem $ docker run -v /etc:/etc-from-host -it ubuntu /bin/bash $ ls /etc-from-host
  • 36. Provided by the database community/vendor. How can I get database image? $ docker run -d -p 27017:27017 --name mongodb mongo $ apt-get install mongodb-clients $ mongo ]
  • 37. Mount volume container. Mounting volumes docker run -v /data/db --name mongodb_data busybox true docker run -d --volumes-from mongodb_data -p 27017:27017 --name mongodb mongo
  • 38. Browse data from the volume. Mounting volumes $ docker run --volumes-from mongodb_data -it ubuntu /bin/bash $ ls /data/db
  • 39. Create backup of the MongoDB data. Backups $ docker run --volumes-from mongodb_data -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /data
  • 41. ip a | grep docker Virtual ethernet bridge
  • 42. Containers can access Internet. Internet can’t access containers. Containers are behind of kinda NAT
  • 43. Docker server can forward ports from containers. Remember MongoDB? $ docker run -d -p 27017:27017 --name mongodb mongo
  • 44. Let the cow count items in collection using linked MongoDB. How container A can access the network of container B? $ docker run --link mongodb:mongodb -it ubuntu /bin/bash $ apt-get update -qqy $ apt-get install -qqy mongodb-clients $ apt-get install -qqy cowsay $ echo 'db.foo.count()' | mongo mongodb:27017 | /usr/games/cowsay
  • 45. Kubernetes for the rescue. Networking is hard
  • 47. The generic approach to connect to the service from your application. Connections failover env:MONGODB_SERVICE_HOST # Kubernetes / Custom mongodb # linked container localhost # localhost
  • 48. The order of the instructions in Dockerfile is important. Build with the caching in mind $ docker build ...
  • 49. Immutable deployment. Use ENV variable to the container. Build once. Run everywhere.
  • 50. Docker Maven plugin by Roland ‘Jolokia’ Huß How can I put a fresh jar into an image?
  • 51. How can I put a fresh jar into an image? <image> <name>${project.artifactId}:${project.version}</name> <build> <from>hekonsek/fatjar:0.0.10-SNAPSHOT</from> <assemblyDescriptorRef>artifact</assemblyDescriptorRef> <exportDir>/jars</exportDir> </build> </image> mvn docker:buid docker:push
  • 52. docker rmi $(docker images -q) Remove images from time to time :)