Intro to Docker
The contents of the the slides have been liberally borrowed from Docker Slideshare materials.
The Challenge
The Matrix from Hell
Docker is a Container System for Code
Docker Eliminates the Matrix from Hell
What is Docker
- At very basic level, think lightweight VM
- Docker is an open platform for developing, shipping, and running applications.
- Run any application securely isolated in a container.
- Open Source engine to commoditize LXC
- Written in Go, runs as a daemon, comes with a CLI
- Full REST API
- Allows to build images in standard, reproducible way
- Allows to share images
VMs vs Containers
Why are Docker Containers Lightweight?
Docker Performance
Booting 15 Openstack VMs
Docker Architecture
The Docker daemon
The Docker daemon runs on a host machine. The user does not directly interact with the daemon, but instead through the Docker client (or API).
The Docker client
The Docker client, in the form of the docker binary, is the primary user interface to Docker. It accepts commands from the user and communicates back and forth with a Docker daemon.
Inside Docker
Docker images
Docker registries
Docker containers
Docker Images
- Docker images are the build component of Docker.
- A Docker image is a read-only template.
- Images are used to create Docker containers.
- Docker provides a simple way to build new images or update existing images, or you can download Docker images that other people have already created.
- Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image.
- When you change a Docker image—for example, update an application to a new version— a new layer gets built.
Docker Registries
- Docker registries are the distribution component of Docker.
- Docker registries hold images.
- These are public or private stores from which you upload or download images.
- The public Docker registry is called Docker Hub. It provides a huge collection of existing images for your use.
Docker Containers
- Docker containers are the run component of Docker.
- A Docker container holds everything that is needed for an application to run.
- Each container is created from a Docker image.
- The Docker image is read-only. When Docker runs a container from an image, it adds a read-write layer on top of the image in which your application can then run.
- Docker containers can be run, started, stopped, moved, and deleted.
Images, Registry, Containers
Docker Commandline
Containers
- docker run creates a container.
- docker stop stops it.
- docker start will start it again.
- docker rm deletes a container.
Images
- docker images shows all images.
- docker import creates an image from a tarball.
- docker build creates image from Dockerfile.
- docker commit creates image from a container.
- docker rmi removes an image.
Info
- docker ps shows running containers.
- docker inspect container info
- docker logs gets logs from container.
- docker events gets events from container.
- docker port shows public facing port of container.
- docker top shows running processes in container.
Building Docker Images
- docker build -t rdocker.mcp.com:5000/api .
- docker push rdocker.mcp.com:5000/api
FROM rdocker.mcp.com:5000/oraclejre
WORKDIR /opt
ADD jars/api.jar /opt/api.jar
EXPOSE 8080
CMD ["java", "-jar", "api.jar"]
Dockerfile
Running a Container
$ docker run -d --name api -p 8080:8080 rdocker.mcp.com:5000/api
- Pulls the api image: Docker checks for the presence of the api image and, if it doesn't exist locally on the host, then Docker downloads it from private docker registry. If the image already exists, then Docker uses it for the new container.
- Creates a new container: Once Docker has the image, it uses it to create a container.
- Allocates a filesystem and mounts a read-write layer: The container is created in the file system and a read-write layer is added to the image.
- Allocates a network / bridge interface: Creates a network interface that allows the Docker container to talk to the local host.
- Sets up an IP address: Finds and attaches an available IP address from a pool.
- Executes a process that you specify: Runs api application
- Captures and provides application output: Connects and logs standard input, outputs and errors for you to see how your application is running.
Managing a Container
$ docker logs api
2014-08-12 23:32:14,193 INFO [pool-1-thread-1] com.datastax.driver.core.policies.DCAwareRoundRobinPolicy --- Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
2014-08-12 23:32:14,198 INFO [main] org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer --- Tomcat started on port(s): 8080/http
2014-08-12 23:32:14,199 INFO [main] com.hds.bel.storage.rest.app.RestApplication --- Started RestApplication in 9.962 seconds (JVM running for 10.619)
2014-08-12 23:32:14,203 INFO [main] com.hds.bel.storage.rest.app.RestApplication --- Running test application org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5ce1f2b6
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c95b8914a58 rdocker.mcp.com:5000/api:latest java -jar api.jar 24 hours ago Up 24 hours api
Image and Container Updates
Conclusion
With Docker, I can:
- Put my software in containers
- Run those containers anywhere
- Write recipes to automatically build containers
- Use same containers for dev, testing, and production.
Learn more at www.docker.io
Copy of Intro to Docker
By Maju Ansari
Copy of Intro to Docker
- 776