Browse Source

intro docker and example

master
zeus 1 year ago
parent
commit
b2ab57f226
  1. 1
      docs/modules/myservices/nav.adoc
  2. 154
      docs/modules/myservices/pages/intro.adoc

1
docs/modules/myservices/nav.adoc

@ -15,6 +15,7 @@
*** xref:poc-datacollector.adoc[Datacollector]
** xref:overview-cloud.adoc[Cloud_and_Services]
*** xref:intro.adoc[Docker Intro]
*** xref:c1.adoc[Creating_Docker_Image]
*** xref:c2.adoc[Volumes_Networking]
*** xref:c3.adoc[Multi_Container_Appl]

154
docs/modules/myservices/pages/intro.adoc

@ -0,0 +1,154 @@
= Docker example - Python
====
http://docs.swarmlab.io/SwarmLab-HowTos/labs/cloud/Intro-Cloud.adoc.html#_containers[Get started with the Docker^]
====
== Docker example - Python
In this example, we will see how we can analyze different data to create the appropriate visualization for the presentation and integrate it into an article.
[TIP]
====
Data can be found here:
The German Climate Computing Center (DKRZ: Deutsches Klimarechenzentrum GmbH) dsaprovides a Long Term Archiving Service for large research data sets which are relevant for climate or Earth system research. This service includes archiving and retrieval capability of data for time periods of 10 years or longer. The long-term archive (LTA) of DKRZ is certified according to the criteria of the Core Trust Seal (CTS) and is, as World Data Centre for Climate (WDCC), accredited as regular member of the World Data System.
or here
https://how-to-open.science/share/open-data/repositories/
https://www.nature.com/sdata/policies/repositories#social
https://github.com/topics/iot-data
https://www.iotcentral.io/blog/great-iot-sensor-and-other-data-sets-repositories
====
To do this we will need the following:
== seaborn
[source,bash]
----
docker run -it --rm -v $(pwd)/documents:/documents resuelve/python:seaborn python3 /documents/plot1.py
----
This command runs a container based on the image resuelve/python:seaborn, and mounts the current working directory's documents folder as */documents* inside the container. The command then executes the python3 */documents/plot1.py* command inside the container. This is likely running a Python script to *generate a Seaborn plot.*
=== Python script
.plot1.py
[source,python]
----
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#Year = [2012, 2014, 2016, 2020, 2021, 2022, 2018]
#Avg = [80, 75.8, 74, 65, 99.5, 19, 33.6]
#data_plot = pd.DataFrame({"Year":Year, "Avg":AVG})
#sns.lineplot(x = "Year", y = "AVG", data=data_plot)
data = pd.read_csv("/documents/plot1.csv", sep='#')
#,. sep = '_' ,. engine = 'python'
info = data.iloc[1:6,:2]
data=data.astype(float)
sns.lineplot(x = "Year", y = "Avg",data=info)
sns.set(style='dark',)
#plt.show()
plt.savefig('/documents/cloud.png')
----
This Python script imports the *Pandas, Seaborn, and Matplotlib libraries* and defines a function to generate a line plot using Seaborn. The script loads *data from a CSV file /documents/plot1.csv* using Pandas' *read_csv()* function, setting *sep='#'* as the separator for the values in the CSV file. The script then selects a subset of the loaded data using the *iloc() *function and passes it to the *sns.lineplot()* function to generate a line plot of the *Year* and *Avg* columns.
After generating the plot, the script sets the style of the plot using the *sns.set()* function and saves the plot as a PNG image at the location */documents/cloud.png* using the *plt.savefig()* function.
====
The code that creates the Year and Avg lists in the comments is not used and is commented out, likely indicating that the data is now loaded from the CSV file instead. The .astype(float) method is applied to the data, likely to ensure that the Year and Avg columns are treated as numeric data. Finally, the plt.show() function is commented out, indicating that the plot is not displayed directly but instead saved to a file.
====
=== csv file
.plot1.csv
[source,csv]
----
Year#Avg
2017#6.5
2018#7.0
2019#7.1
2020#7.3
2021#7.5
2022#7.4
----
====
Pandas, Seaborn, and Matplotlib libraries Description
* Pandas: Pandas is a powerful data analysis library for Python. It provides data structures for efficiently storing and manipulating large datasets, as well as tools for data cleaning, transformation, and analysis. Pandas is particularly well-suited for working with tabular data, such as data stored in CSV or Excel files.
* Seaborn: Seaborn is a data visualization library for Python that is built on top of Matplotlib. It provides a high-level interface for creating beautiful and informative statistical graphics, including heatmaps, scatter plots, line plots, and more. Seaborn is particularly well-suited for working with complex datasets, such as those with multiple variables or non-linear relationships.
* Matplotlib: Matplotlib is a 2D plotting library for Python that provides a wide range of tools for creating static, animated, and interactive visualizations. It provides a low-level interface for creating a wide range of plots and charts, including scatter plots, line plots, bar charts, histograms, and more. Matplotlib is particularly well-suited for creating publication-quality figures and graphics, and is widely used in scientific research and data analysis.
====
== asciidoctor
[source,bash]
----
docker run -it --name=swarmlab-adoc -v $(pwd)/documents/:/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf --safe -a toc -o /documents/example2.adoc.pdf /documents/example2.adoc
----
This command runs a container based on the image *asciidoctor/docker-asciidoctor*, and mounts the current working directory's documents folder as */documents* inside the container. The command then executes the *asciidoctor-pdf --safe -a toc -o /documents/example2.adoc.pdf /documents/example2.adoc* command inside the container, which likely generates a PDF document from an AsciiDoc file located at */documents/example2.adoc.*
.include figure in asciidoc
[source,adoc]
----
.Image caption
image::cloud.png[I am the image auto generated.]
----
TIP: more info here https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/#ex-footnotes[syntax-reference^]
=== Asciidoctor Description
Asciidoctor is a lightweight markup language and text processor that is used to create documentation, technical manuals, and other technical content. It is written in Ruby, but can be used with many other programming languages, including Java, Python, and JavaScript.
Asciidoctor provides a simple syntax for writing structured documents, including headings, lists, tables, and other elements. It also includes support for cross-references, footnotes, bibliographies, and other advanced features.
Asciidoctor can be used to convert documents written in its markup language into a variety of output formats, including HTML, PDF, EPUB, and more. It also includes support for customizing the output format and styling of the final document, making it a powerful tool for creating polished, professional-looking documentation.
====
*Latex and Asciidoctor*
LaTeX is a document preparation system that is widely used for typesetting technical and scientific documents, including research papers, reports, and books. It provides a high-level markup language that allows users to specify the structure and content of a document, as well as tools for typesetting mathematical formulas, equations, and other technical content.
LaTeX provides a wide range of features for creating beautifully typeset documents, including automatic numbering of sections and equations, bibliography management, cross-referencing, and more. It is particularly well-suited for creating complex technical documents that require precise formatting and layout, such as research papers, theses, and dissertations. It is widely used in academic and scientific publishing, and is popular among mathematicians, scientists, and engineers.
Asciidoctor, on the other hand, is a lightweight markup language and text processor that is designed for creating technical documentation, such as user manuals, API documentation, and other technical content. It is well-suited for creating documents that are intended to be read online, such as wikis and documentation websites.
When deciding between Asciidoctor and LaTeX, it's important to consider the specific needs of your project. If you are creating academic papers or technical reports with complex mathematical formulas or scientific notation, LaTeX may be the best choice. On the other hand, if you are creating technical documentation or user manuals that are intended to be read online, Asciidoctor may be a better fit. Additionally, Asciidoctor may be easier to learn and use for those who are not familiar with the TeX typesetting language or the LaTeX toolchain.
====
== okular
[source,bash]
----
docker run -it --name=swarmlab-adoc-pdf --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v $(pwd)/documents:/documents silvavlis/okular /documents/example2.adoc.pdf
----
This command runs a container based on the image *silvavlis/okular*, and mounts the current working directory's documents folder as */documents* inside the container. The command then executes the */documents/example2.adoc.pdf* command inside the container, which likely opens the generated PDF file in the Okular PDF viewer. The *--net=host* option allows the container to access the host machine's network, the *--env="DISPLAY"* option sets the DISPLAY environment variable to *allow GUI applications* to display on the host machine's X server, and the *--volume="$HOME/.Xauthority:/root/.Xauthority:rw"* option shares the host machine's X authority file with the container to allow X authentication.
Loading…
Cancel
Save