This document discusses Docker, including:
1. Docker is a platform for running and managing Linux containers that provides operating-system-level virtualization without the overhead of traditional virtual machines.
2. Key Docker concepts include images (immutable templates for containers), containers (running instances of images that have mutable state), and layers (the building blocks of images).
3. Publishing Docker images to registries allows them to be shared and reused across different systems. Volumes and networking allow containers to share filesystems and communicate.
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
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
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
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 ...
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