What Is a docker-compose.yml File?

Question
What is a docker-compose.yml file?

Answer
It is a file used by the docker-compose utility which orchestrates the creation of multiple containers. For microservices, SOA and various stacks of applications (e.g., the LAMP stack), container orchestration is useful. Here are some quotes which help elucidate what docker-compose does:

"Compose is a tool for defining and running multi-container Docker applications." (Taken from Docker's website.)

"In order to do something useful with containers, they have to be arranged as part of a project, usually referred to as an ‘application’. This is what a docker-compose.yml file does, specifying what images are required, what ports they need to expose, whether the have access to the host filesystem, what commands should be run, and so on." (Taken from Divio.com.)

"A docker-compose.yml file is a YAML file that defines how Docker containers should behave in production." (Taken from Docker's website.)

The docker-compose is "a command-line utility to define and run multicontainer applications with Docker." taken from page 198 from The Docker Cookbook by Goasguen.

The docker-compose utility looks for and uses a docker-compose.yml file in the directory that you run the "docker-compose" command. This utility supports the keyword "depends" in the docker-compose.yml file. This "depends" conditions a container starting on another container starting. If you run "docker-compose up foobar" (where foobar is a service in the docker-compose.yml file), the command will start the services that "foobar" depends on, as designated in the docker-compose.yml file. Without specifying a service name, the docker-compose up command will start all of the services.

Here is an example of a docker-compose.yml file:

version: '3'
 services:
   db:
      image: mysql
      container_name: mysql_db
      restart: always
      environment:
         - MYSQL_ROOT_PASSWORD="secret"
   web:
     image: apache
     build: ./webapp
     depends_on:
        - db
     container_name: apache_web
     restart: always
     ports:
       - "8080:80"

The above was taken from from Tecadmin.net.

If you want to try a docker-compose.yml file out, see this posting.

To learn more about the file itself and its reserved words, see this.

How Do You Troubleshoot Jenkins Pipelines Not Running when You Try to Execute Them?

Problem scenario
Your Jenkins pipeline jobs will not run. You see "Build Scheduled" when you click on the "Build now" link. But nothing happens. You see an error that your /var/lib/jenkins/ is running low on disk space. You have no access to the back-end of the server that runs Jenkins. What should you do?

Solution
Look at the dashboard view. Next to the date and time of the most recent success of the job (build, project or pipeline) will be an integer number (e.g., 1, 53, 840 etc.). Find a job that has the largest integer value. See if you can delete the previous builds -- or more efficiently, delete the entire project. It may take 30 minutes, but eventually this will free up disk space.

How Do You Use a PowerShell Command to Stop an Azure VM?

Problem scenario
You have a server in Azure you want to turn off. What should you do to stop it?

Solution
Prerequisite
You need to know the server's name and resource group. You can do this by finding the server in the Azure Portal.

Procedures
Run this command:

Stop-AzureRmVM -ResourceGroupName $nameOfResourceGroup -Name $nameOfVM

# Replace $nameOfResourceGroup with the name of the Resource Group.  Replace $nameOfVM with the name of the the VM.

How Do You Install Apache Rya on Any Distribution of Linux?

Problem Scenario
You want to install Apache Rya on Linux. What do you do?

Solution

Prerequisites
i. You need a server with at least 5 GB of total memory. You can create swap space with this posting. (Remember that 1 GB of RAM and 2 GB of swap space will be insufficient for installing Rya.)
ii. You need a server with at least 30 GB of free space.
iii. Java and Maven must be installed. If you have a Debian or Ubuntu distribution of Linux and you need assistance installing Java, run this: sudo apt install default-jdk
For any other distribution of Linux you can see this posting for help on installing Java and this posting for installing Maven.
iv. Install git if it has not been installed. To do this on a RedHat derivative of Linux (e.g., CentOS/RHEL/Fedora), you could run this: sudo yum -y install git

Procedures
Run these commands:

git clone https://git-wip-us.apache.org/repos/asf/incubator-rya.git 

cd incubator-rya

mvn clean install -Drat.numUnapprovedLicenses=350
# The above command can take 90 minutes to run.

# The next commands are optional if you want to install the Rya command shell:

sudo find / -name rya.shell*tar.gz

Copy the file into /bin/ (e.g., sudo cp /path/to/file/found/above/rya.shell...tar.gz /bin/)
cd /bin/
sudo tar -xzvf rya.shell*tar.gz
cd rya.shell*
sudo bin/rya

From the rya prompt run this: version
This proves it was installed correctly.

(According to Forbes, triplestore databases are NoSQL.)

Using Python How Do You Write a Palindrome Tester with Special Requirements?

Problem scenario
You want to write a Python that will test if a string is a palindrome with two other requirements. One requirement is to not use a "::" (a colon pair) in the code. The second requirement is to search for a substring that is a palindrome if the full string is not a palindrome. This substring is not any substring however: it must include the leftmost character. For this requirement we will consider a one-character string to be a palindrome.

How do you create a palindrome testing function without using a double colon that tests for substrings to be palindromic if the entire string is not a palindrome?

Solution
Here is the code:

def palindrome_tester(string_to_test):
    if (len(string_to_test) == 1):
        return string_to_test
    tempa = list(string_to_test)  # Make the string a list for reversibility
    tempa.reverse()
    for x in range(0, len(tempa)):
        # Convert the tempa list to a string via the str func, map func
        # and the join method
        string_test = ''.join(map(str, tempa))
    if (string_test == string_to_test):
        return string_to_test
    else:
        # Remove the rightmost character and test resulting string
        string_to_test = string_to_test[:-1]
        # When using recursion, use the return keyword
        return palindrome_tester(string_to_test)

string_to_test = input("Enter a string: ")
result = palindrome_tester(string_to_test)
print("The longest palindrome that can be made of the characters is:")
print(result)

How Do You Use a PowerShell Command to Destroy an Azure VM?

Problem scenario
You have a server in Azure you no longer need. You want to save money by deleting it. What should you do to eliminate it?

Solution
Prerequisite
You need to know the server's name and resource group. You can do this by finding the server in the Azure Portal.

Procedures
Run this command:

Remove-AzureRmVM -ResourceGroupName $nameOfResourceGroup -Name $nameOfVM

# Replace $nameOfResourceGroup with the name of the Resource Group.  Replace $nameOfVM with the name of the the VM.

A List of Books on Site Reliability Engineering

Here is a list of SRE books:

How Do You Troubleshoot the Ansible Message “Syntax Error while loading YAML. expected , but found ””?

Problem scenario
You run an Ansible playbook with a variable. But you get this message: "ERROR! Syntax Error while loading YAML. expected , but found ''" (Ansible found blank single quotes or a double quote mark.)

How do you get the playbook to run?

Solution
Notice the "offending line" in the message. Remove the braces and possibly the quotes around the braces. Assign the variable by itself (without the braces syntax).

Do not use a variable like this:

tasks:
     - shell: "echo  > /tmp/date.txt"
       when: {{ ansible_hostname }} == "contintserver"

or like this:

- shell: "echo  > /tmp/date.txt"
  when: "{{ ansible_hostname }}" == "contintserver"

Here would be a correct snippet:

- shell: "echo  > /tmp/date.txt"
  when: ansible_hostname == "contintserver"

How Do You Troubleshoot the Message “Error: Config file not found: /usr/lib/jvm/java-9-openjdk-amd64/conf/management/management.properties”?

Problem scenario
You are trying to run Apache Zookeeper or some other application. You enounter the problem Error: Config file not found: /usr/lib/jvm/java-9-openjdk-amd64/conf/management/management.properties. What should you do?

Possible solution
This is a workaround. Run these commands:
sudo mkdir -p /usr/lib/jvm/java-9-openjdk-amd64/conf/management/
sudo touch /usr/lib/jvm/java-9-openjdk-amd64/conf/management/management.properties

Why Does Your Python Function Return None?

Problem scenario
Your Python function prints out the value of the variable immediately before it returns the variable.  When it is assigned via the "return" statement, the value is "None".  You were expecting an integer or some other value.  What is wrong?

Solution
Does your function use recursion?  If it is using recursion rather than merely calling the function and it returns "None", use the return statement.  For example, this would cause the problem:

def coolfunction(x):
    ....
    coolfunction(x)

This rewrite of the above would solve the problem of the unwanted "None" returning from your function:

def coolfunction(x):
    ....
    return coolfunction(x)