Docker is a tool that allows applications to be packaged into containers that provide isolation and portability. Containers use less resources than virtual machines and allow applications and their dependencies to be easily deployed. The Docker engine runs containers using images, which are templates that contain instructions for creating containers. Docker Compose allows defining and running multi-container applications, and tools like Portainer provide graphical interfaces for managing Docker containers.
"Impact of front-end architecture on development cost", Viktor Turskyi
DockerCC.pdf
1. DOCKER
[ Docker ]
Todo lo que quiso saber sobre Docker y seguramente ya tuvo oportunidad de escuchar
César Capillas <cesar at zylk.net>
2. DOCKER
This talk contains:
● Intro
● Docker engine and definitions
● How to use Docker Images
● How to create Docker Images
● Hands on Docker
● Advanced concepts: docker-compose, portainer
3. DOCKER
A container (what is this ?)
● It is an operating system process, that provides:
● A standarized packaging for software and dependencies
● Isolation of apps from each other
● It is not a virtual machine, but it is often compared.
● It provides isolation in terms of:
● Network, Process, User…
● One important feature is that data is ephemeral by default
5. DOCKER
Benefits
● Lightweight / Speed
● No OS to boot applications online in seconds
→
● Highly Portable
● Ability to move between infrastructure
● Easily and quickly provisionable
● Real time provisioning
● Efficiency:
● Less OS overhead
● Native system performance
7. DOCKER
The Docker engine
● It’s a client-server app for running containers
● A server engine (process) with a daemon process called
dockerd
– It provides a REST API for talking with docker
● A command line interface docker (CLI):
– It runs containers
– It is able to manage network and volumes (storage)
9. DOCKER
The Docker family
● Two versions:
● Docker Community Edition
– Free, community-supported product for delivering a
container solution
● Docker Enterprise Edition
– Subscription based, commercially supported for
delivering a secure software supply chain
10. DOCKER
The Docker basics
● Image: Read-only template with instructions for creating a
Docker container.
● Container: Runnable instance of an image.
● Data Volume: Storage folder inside or outside of an image.
● Network: Network interface to connect the container to
default network.
12. DOCKER
Sharing images
● Docker Registry
● You obtain Docker Images from a public (or private)
registry (repository of images)
● When building an image, it is only available in local
● Then you may need to push to a registry
– Docker Hub
– Nexus 3
● Once shared, other people can pull the image
13. DOCKER
Creating images
● Using “Dockerfile”
● FROM Desde qué imagen parto
→
● ENV Definir variables de entorno
→
● ADD Añadir un archivo local en la imagen
→
● COPY
● RUN
● CMD
14. DOCKER
[ Hands on ]
$ mkdir work
$ cd work
$ git clone https://zgit.zylk.net/alfresco/imasd/dx-dockerlab.git
$ cd dx-dockerlab
15. DOCKER
Hands on
0)Prerrequisites (install docker environment)
1)Package and build a custom app with Docker
2)Remembering Tomcat (Revenge)
3)Use commercial databases with Docker (SQL Server)
4)Using docker-compose
5)Docker resources for Apache SOLR
6)Docker resources for Liferay
7)Docker resources for Alfresco
16. DOCKER
Example 1: Deploying a war in Tomcat
FROM tomcat:8.0-alpine
ADD apps/jolokia.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]
# Compilo la custom image con el fichero Dockerfile
$ docker build -t myjolokia .
# Creo el contenedor y lo ejecuto en foreground
$ docker run -p 8888:8080 myjolokia
17. DOCKER
Common commands in Docker
$ docker -v
Docker version 19.03.6, build 369ce74a3c
# Para ver tus imágenes locales
$ docker images
# Para ver los containers-id’s que se estan ejecutando
$ docker ps
$ docker ps -a
# Para ejecutar una imagen de docker en background
$ docker run -d <docker-image>
# Para ver los logs de un container
$ docker logs -f <container-id>
# Para inspeccionar el container que estás ejecutando
$ docker exec -it <container-id> /bin/bash
# Para buscar imágenes en Docker Hub
$ docker search tomcat
# Para descargar una imagen
$ docker pull mcr.microsoft.com/mssql/server:2017-latest
18. DOCKER
Example 2: Remembering Tomcat
● Change server.xml configuration file in Tomcat to work in
8998 port instead of default 8080.
● Change in Dockerfile the corresponding port nating.
● 8888 8998
→
● Customize JVM options in setenv.sh to set Memory Heap
● -Xmx1024m
● Check Tomcat logs
● How to set Docker machine in background ?
19. DOCKER
Example 2: Remembering Tomcat
FROM tomcat:8.0-alpine
ADD config/server.xml /usr/local/tomcat/conf/server.xml
ADD config/setenv.sh /usr/local/tomcat/bin/
ADD apps/jolokia.war /usr/local/tomcat/webapps/
EXPOSE 8998
CMD ["catalina.sh", "run"]
# Compilo la custom image con el fichero Dockerfile
$ docker build -t myjolokia2 .
# Ejecuto el docker en background
$ docker run -d -p 8888:8998 --name=mytomcat8 myjolokia2
20. DOCKER
Example 3: Using commercial databases
$ docker pull mcr.microsoft.com/mssql/server:2017-latest
$ docker run -d -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=7y1K7y1K!" -p
1433:1433 --name sqlserver2017 --hostname sqlserver2017 -d
mcr.microsoft.com/mssql/server:2017-latest
# First we can try to check if the default port is available:
$ nc -v localhost 1433
Connection to localhost 1433 port [tcp/ms-sql-s] succeeded!
21. DOCKER
An example: Using MS-SQLServer
# In the following, we are going to create a database for Alfresco. A
possibility is to run sqlcmd utility inside docker machine:
$ docker exec -it sqlserver2017 "bash"
root@de2f9e36fd46:/# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P
'7y1K7y1K!'
1> CREATE DATABASE alfresco6
2> SELECT Name from sys.Databases
3> GO
master
tempdb
model
msdb
alfresco6
1> ALTER DATABASE alfresco6 SET ALLOW_SNAPSHOT_ISOLATION ON;
2> GO
1> QUIT
23. DOCKER
Composing images with Docker Compose
● Docker Compose
● Provides the composition of a defined setup with
several Docker images.
● It uses a YAML file (docker-compose.yml)
● It defines, networks, ports, services, enviroment
variables…
● $ docker-compose up
24. DOCKER
Example 4:
●
Define local volume to preserve tomcat logs in local.
● Set mem_limit for this service
● Set JVM variables and db.driver in JAVA_OPTS
●
Add extra_hosts for connecting to external mysql (sqldev host)
25. DOCKER
Example 4:
●
What is the problem in this compose ?
version: '3.1'
services:
tomcat:
image: tomcat:8.0-alpine
ports:
- 8888:8080
volumes:
- ./logs:/usr/local/tomcat/logs
mem_limit: 1500m
environment:
JAVA_OPTS: "
-Ddb.driver=org.gjt.mm.mysql.Driver
-Xms512m -Xmx1024m
"
extra_hosts:
- "sqldev.zylk.net:192.168.1.100"
29. DOCKER
Using Portainer for docker management
● Making Docker Management Easy
● https://www.portainer.io/
30. DOCKER
Managing Images
● A Docker Swarm node to manage remotely Docker
containers.
● Provides a graphical interface for creating and executing
docker images via Docker Compose.
● It is able to use a local registry (Nexus) for custom Docker
images.
33. DOCKER
Zylk for reading (Blog Post)
● Using MS-SQLServer with a docker container for developing (outdated)
●
https://www.zylk.net/es/web-2-0/blog/-/blogs/using-docker-image
s-for-enterprise-databases-with-alfresco
● Managing docker images for generating production infrastructure
● https://www.zylk.net/es/web-2-0/blog/-/blogs/managing-docker-i
mages-for-generating-production-infrastructure
● Testing new features on products with Dockerfiles
● https://www.zylk.net/es/web-2-0/blog/-/blogs/testing-new-feature
s-in-elastic-search-7-with-docker
●
Analyzing logs with Elastic and Docker.
● https://www.zylk.net/es/web-2-0/blog/-/blogs/analyzing-tomcat-lo
g-access-data-with-docker-elk-resources