Problem scenario You run this command: docker run -it ubuntu bash
docker: Got permission denied while trying to connect to the Docker daemon sockes/create: dial unix /var/run/docker.sock: connect: permission denied.
You do not want to run a Docker container as a privileged user (as a recommended practice). What should you do?
Solution Background: "To do builds in the cluster, it is essential to run the build without root privileges." This quote was taken from page 222 of Kubernetes Patterns by Bilgin Ibryam and Roland Huß (O'Reilly). Copyright 2019 Bilgin Ibryam and Roland Huß, 978-1-492-05028-5. Prerequisites Install Docker. If you need assistance, see this posting.
Procedures 1. Run these commands:
sudo newgrp docker
exit
sudo usermod -aG docker jdoe
# Replace "jdoe" with the user you want to run the Docker container with. You can use "whoami" manually to find out what user you are.
2. If you were logged in as jdoe (the user you just added), log out and log back in.
3. Now try again (e.g., run docker run -it ubuntu bash).
You may also want to see this external posting for additional assistance.
Problem scenario You want to test your OpenLDAP configuration. You run an "ldapsearch -x" command in hope that it wil l return a "Success." You run the "ldapsearch -x" command, and you see this:
"# search result search: 2 result: 32 No such object"
What should you do?
Solution Verify your /etc/ldap/ldap.conf is configured correctly. The BASE stanza should have one or possibly three "dc=" entries separated by commas.
The URI stanza should have FQDNs or internal IP addresses depending on your configuration. Here is an example of such stanzas from a working ldap.conf file (from a Linux server in Google Cloud Platform):
BASE dc=c,dc=brave-fudge-193019,dc=internal URI ldap://10.142.0.2 ldap://10.142.0.2:666
Problem scenario You have a web-based email provider. You want to save all of your emails in one location quickly. How do you download them into one file?
Solution If there are maximum size limits for sending a single email (e.g., 25 MB), this method may not work if all of your emails put together exceed this size limit.*
1. Click an option to select all emails. Find a mail icon with a down arrow on the top column and click it with the mouse. Choose "All".
2. Then right click one of the highlighted emails and choose "Forward as attachment."
3. Forward your emails to yourself or save it as a draft.
4. When this email arrives or from your Drafts folder, select the check box for this email and choose "Download (.eml)". Now you should have a file with all of your emails.
* Alternatives may include using Outlook or Thunderbird to manipulate your email. Some web-based email providers support Outlook or Thunderbird configurations.
Problem scenario This command is not working for you: sudo apt --fix-broken install
You get a message like this:
dpkg: error processing archive /var/cache/apt/archives/puppet_4.8.2-5_all.deb (--unpack): trying to overwrite '/lib/systemd/system/puppet.service', which is also in package puppet-agent 5.4.0.522.g6baf971-1xenial dpkg-deb: error: subprocess paste was killed by signal (Broken pipe) Errors were encountered while processing: /var/cache/apt/archives/puppet_4.8.2-5_all.deb
You try this command: sudo apt-get purge -s puppet*
You cannot remove a package. You get a series of errors. The errors seem to be circularly related and interdependent. What should you do?
Solution Run these commands:
sudo apt-get update --fix-missing
sudo apt-get -y remove puppet-agent puppet-master puppet # try to remove the package and related packages. Replace "puppet-agent puppet-master puppet" with the packages you want to be removed.
Problem scenario You do not want to install wget on Linux. You want curl to download a file from the internet. How do you get curl to work through a forwarding request the same way wget natively works?
Problem scenario You have heard of processes and threads in Python. Are there illustrative Python programs that use processes and threads to demonstrate the differences between processes and threads themselves?
Solution Here are two differences between processes and threads in Python:
Difference #1 Children processes keep running when parent process is killed. Child threads stop processing when parent process is killed.
Python script A (with spawned threads):
""" This program spawns no other PIDs. In a duplicate terminal session, running the Linux command "sudo ps -ef | grep nameofprogrambelow.py" will show that no other PIDs are spawned when it executes."""
import _thread as thread, time
def counter(myId, count):
for i in range(count):
time.sleep(1) # Don't adjust this time. The time on penultimate line is adjustable for experimentation and learning.
print('[%s] => %s' % (myId, i))
for i in range(5):
thread.start_new_thread(counter, (i, 5))
time.sleep(6) # This duration affects the function b/c it too has time.sleep(1)
print('Main thread exiting.')
Python script B (with process forks):
"""This program spawns other PIDs. In a duplicate terminal session, running the Linux command "sudo ps -ef | grep nameofprogrambelow.py" will show other PIDs are spawned when it executes.
The program below really does exit when you see "The main process has exited..." Running this program will demonstrate the ability of child processes to survive their parent processes pre-termination:"""
import os, time
def pidprinter(count):
for i in range(count):
time.sleep(1)
print('[%s] => %s' % (os.getpid(), i))
if (i == (count - 1)):
print("Press enter to get to a command prompt.")
for i in range(7):
pid = os.fork()
if pid != 0:
print('Process %d spawned' % pid)
else:
pidprinter(7)
os._exit(0)
print('The main process has exited. The following processes demonstrate existence without a parent process.')
Difference #2 If a Python program spawns a new process, Python waits for that process to return a value before interpreting the next line.
If a Python program starts a new thread, Python continues processing the next lines of code and does not wait for that thread to return a value before interpreting the next line.
Python script C (invokes threads only)
"""Running this Python program shows that the sleep(30) call (which normally makes a program wait for 30 seconds) is not invoked because threads do not cause the Python interpreter to wait for a return value:"""
import _thread as thread, time
def counter(myId, count):
for i in range(count):
time.sleep(30)
print('[%s] => %s' % (myId, i))
return myId
x = thread.start_new_thread(counter, (0, 5))
print(x)
print("Got here")
print('Main thread exiting.')
Python script D (invokes processes only)
"""Running this Python program shows that the sleep(30) call is invoked because processes cause the Python interpreter to wait for a return value:"""
import os, _thread as thread, time
def counter(myId, count):
for i in range(count):
time.sleep(30)
x = os.getpid()
return x
x = counter(0, 5)
print(x)
print("Got here")
print('Main thread exiting.')
Problem scenario You run a command like this: docker login docker.artifactory
You receive a message like this: "Error response from daemon: Get https://docker.artifactory:80/v1/users/: dial tcp x.x.x.x:443: i/o timeout"
What should you do?
Solution Make sure there is no firewall or security group blocking connectivity from the client reaching the Docker registry. Even if you are running the "docker registry" command from the back-end of the Docker registry server itself, this error can happen if the server is in a security group that does not allow connectivity to itself. Can you ping Docker registry server? Does the hostname resolve properly? Once you can ping it, then the problem should not happen.
Problem scenario You are trying to write a simple Groovy program. You have an array of individual strings. How do you assign one of them to be the value that a variable is?
Solution To assign an element of an array, should have quotes around the variable and the $ symbol and the syntax " as String" should follow the closing quote mark.
def input = System.console().readLine 'Please provide some input: '
def x = input
def boardArray = new String[2]
boardArray[0] = ""
boardArray[1] = ""
boardArray[1] = "$x" as String //This is the correct version
println boardArray[1]