Skip to main content

Posts

How to login to a running Docker container as root?

How to login to a running Docker container as root? ------------------------------------------- ---- TL DR: docker exec -it --user root <container> bash ------------------------------------------- ---- Most of the times the application would run in a different user. as specified in the docker file. Such a docker file is mentioned below. FROM openjdk:17-alpine RUN apk update && apk add --no-cache gcompat && apk add curl bash RUN addgroup -S appuser && adduser -S appuser -G appuser USER appuser:appuser # some custom code to run an app In this Dockerfile the line " USER appuser:appuser" specifies the user and group which the application should run. Also, any commands following this line will run as the same user, and if you login the container without specifying the user explicitly, it will be the default user. eg: Docker exec accepts another parameter to specify the user. With that we can login as root or any user we want. 

WSL enable copy/paste shortcuts

 I moved to Windows recently, but still, I need Ubuntu installed in WSL for some of my work. You can enable Ctrl + Shift + C / Ctrl + Shift + V shortcuts for copy/paste. Right-click on the title bar and select Properties from the context menu. In the Options tab, tick the Use Ctrl+Shift+C/V as Copy/Paste option. Click OK. Now, we are good to copy/paste similar to the Ubuntu native shortcuts.

Install Docker on Windows 11 with WSL Ubuntu 22.04

This is to install Docker within Ubuntu WSL without using the Windows Docker application. Follow the below steps. Install Ubuntu 22.04 WSL 1. Enable Windows Subsystem for Linux and Virtual Machine platform Go to Control Panel -> Programs -> Programs and Features -> Turn Windows features on or off 2. Switch to WSL 2 Open Powershell and type in the below command. wsl --set-default-version 2 If you don't have WSL 2, download the latest WSL 2 package and install it.  3. Install Ubuntu Open Microsoft Store and search for Ubuntu. Select the version you intend to install. I'd use the latest LTS version Ubuntu 22.04. Click on the Get button. It will take a couple of minutes to download and install. 4. Open up the installed Ubuntu version that was installed. If you get an error like the below image, make sure to install the WSL2 Kernel update .  If it's an older Ubuntu version the error message would be something like the image below. Error: WSL 2 requires an update to its ...

Ubuntu DNS issue fix DNS_PROBE_FINISHED_BAD_CONFIG

Issue  I've been playing with a VPN and somehow it messed up my DNS resolution configurations. Chrome gives  DNS_PROBE_FINISHED_BAD_CONFIG  error and can't ping google. So it seemed to be an issue with the DNS. Of course, restarting didn't fix it. I tried DNS lookup which gave me below. To make sure this is somehting to do with my DNS confgis, I ran the same by providing the google DNS servers.  It works, which means my default DNS is not working for some reason. To make sure this, ran the below command. systemd-resolve --status Output has an entry for DNS Servers, which was  ::1 Fix 1. Edit the file /etc/systemd/resolved.conf. sudo vi /etc/systemd/resolved.conf 2. Add new DNS entries. I added 2 google DNS and the cloudflare DNS sever. [Resolve] DNS=8.8.8.8 8.8.4.4 1.1.1.1 3. Restart the systemd-resolved and check the configuration is persisted in /run/systemd/resolve/resolv.conf file. sudo service systemd-resolved restart cat /run/systemd/resolve/resolv.co...

Fix Error with git even after adding the public key. Git bash Permission denied (publickey).

 This could be a common issue while using git bash in windows.  Before fixing this issue, it is assumed that the public/private key pair is generated and the public key is configured in the git server (github, bitbucket or whatever). Still, if you get the "Permission denied (publickey)." which means, the ssh agent might not have recognized your key. To solve this you'll have to make sure the ssh agent is running and the key is added. Run the ssh agent, execute the below command in git bash exec ssh-agent bash To check if the key is added run the below command. ssh-add -l If there is no key, it will print "The agent has no identities." To add the key, run the below command with the path to your private key. ssh-add ~/.ssh/thilinarsa (My key file is located in C:/User/Thilina/.ssh/thilinarsa) If you run the ssh-add -l command again you should see the key file added. Run the git clone or pull command again and see if it works!

Facebook videos are too loud

Not sure if it is only me, but as of this writing, I find some of the Facebook videos are too loud compared with other websites or players on the machine. Whenever I play a video, I usually turn the volume down. Then whenever there's an ad, it screams in my ears. Same when I play the next video, the former adjusted volume level doesn't stick. This could be a bug in FB, so I even suggested a feature improvement.  As a solution, I found this chrome plugin. Sound and video fixes for Facebook Don't know who developed it, but the dude has fixed one of Facebook's problems, and many thanks to the developer. I might as well help him out as it is an open-source project. No more screaming videos! 

A Silly New Year Wish with a Java code

TJ's silly new year wish Happy New Year y'all!!! package com.tjisblogging ;   import java.time.LocalDate ; import java.time.Month ; import java.util.Vector ;   public class NewYear {   private static final LocalDate END_OF_2022 = LocalDate . of ( 2022 , Month. DECEMBER , 31 ) ;   public static void main ( String [ ] args ) { Life yourLife = Life. getInstance ( ) ; while ( ! LocalDate. now ( ) . equals ( END_OF_2022 ) ) { yourLife. push ( "Love" ) ; yourLife. push ( "Joy" ) ; yourLife. push ( "Happiness" ) ; yourLife. push ( "Prosperity" ) ; yourLife. push ( "Money" ) ; yourLife. push ( "Health" ) ; } } }   class Life { private Vector < String > lifeQueue = new Vector <> ( ) ; private static Life instance = new Life ( ) ;   private Life ( ) { }  ...

How to resolve Log4j CVE-2021-44228 in Spring Boot

 As you may know, Log4j released a patch (actually a couple of patches) recently for a vulnerability  [CVE-2021-44228] that was identified in their library. Since a lot of Spring boot applications are out there using Log4j 2.x series. It is better to fix them as soon as possible.  Also, this article is considering you are using Maven for dependency management. Fixing this in the Spring boot applications is easy. It is just adding a version property for the pom.xml.  As of this date of writing, the latest updated Log4J version is  2.17.1 . So the fix is to update the version property with this. <properties>     <log4j2.version>2.17.1</log4j2.version>     <log4j.version>2.17.1</log4j.version> </properties> If you are using BOM, instead of spring boot parent dependency, update it as follows. <dependencyManagement>     <dependencies>         <dependency>   ...

AWS add multiple MFA devices

 Adding multiple MFA devices to AWS user account I wanted to use more than one device for MFA. Well, once I was abroad and my phone broke for some time. My phone had  MFA setup for the AWS account. Then I was locked out and couldn't log in to AWS without having the phone. This made me wanted to keep more than one MFA device. However, AWS doesn't really allow you to add more than one device. It is to note that we always use virtual MFA devices and that is also the trick to do this. I haven't tried this with hardware devices though. Just to be clear a virtual MFA allows us to set up an MFA application such as Google Authenticator or Microsoft Authenticator etc.  The Workaround The trick is to use the same QR code to add another device. Also, this can be done using the secret too. When the first device is added, keep the QR code (maybe take a screenshot and then add another MFA device.  Scan the same QR code with the next device or enter the secret key. The same pin num...

Ubuntu MySQL ERROR 1698 (28000)

Ubuntu MySQL ERROR 1698 (28000): Access denied for user 'root'@'localhost'  This is a quick note about MySQL root access error in Ubuntu even though the password is correct.

Moodle Enable HTTPS with a proxy or an ELB

 If you are converting Moodle site from HTTP to HTTPS or setting up from the scratch, it will be a bit tricky as I also experienced. By the way, I'm not going to talk about how to install the SSL certificate here. This is only about the Moodle configurations you have to do after that. There are two ways you can do this. 1. Enable HTTPS using a proxy or an ELB If you have this setup, then again we need to change the config.php as below. //Change the URL to https $CFG->wwwroot = ' https ://my.moodle.site.edu'; //Add the following line $CFG->sslproxy = true; If the SSL proxy configuration is not enabled, your browser will keep trying to redirect.  You should enable this configuration if you have SSL termination from a proxy or a load balancer. I tried this with an AWS ALB (Application Load Balancer).  If you don't change the config, it will fail to load the styles and Javascript. 2. Enable HTTPS in Apache server This is if HTTPS is enabled in the Apache server on...

Automatically open Chrome developer tools in a new tab

Sometimes we need to check the console or the network transactions of a link that opens up in a new tab. By default, the Chrome developer tools are not opening in a new tab. So, by the time when we hit F12 and open the dev tools, part of the information we needed could be already gone.  There's a setting in dev tools where you can keep the dev tools open automatically in a new tab. To enable that, hit F12 and open up the dev tools. Click on the settings icon in the top right corner. In the Preferences section, scroll down to the bottom. You'll be able to find the option to Auto-open DevTools for popups. Select the checkbox and we're good to go!

How to access a container in Rancher from the command line

How to access a container in Rancher from the command line without SSH If you have deployed an application pod in rancher, sometimes you have to access the running container for various tasks. Maybe, to check some files, monitor logs, run some commands, copy files, etc.  Assume you have an application pod running in Rancher as the following image. Using the Web UI One of the ways to access the container would be using the Rancher UI. If you click on the pod name and then on the next page, you can select Execute Shell from the Pod's context menu. Then it is supposed to bring the command window in the web UI itself. However, this method has its limitations. You cannot copy files to or from the Pod using the web UI itself.  Using Rancher CLI The link to the CLI package can be found in the bottom right corner of the Rancher web UI. Select the CLI client according to your OS and download. I'm using Linux, so I've downloaded the Linux client.  Extract it. tar -xf rancher-linux-...

TJ's theory of human evolution

Human evolution from the eyes of a programmer From the first life that appeared on Earth, there have been so many species that came into existence. As Darwin showed, a species can evolve from a common ancestor into a specific species with unique properties and behaviors of its own. Each species may possess some abilities based on its properties and behaviors. The abilities of a species can be used to get an understanding of development and intelligence. For example, a simple microorganism would only show the capabilities of primitive life i.e. energy consumption, reproduction, growth, and development. However, a developed higher species may display abilities like building nests, homes, communication with sound patterns, etc.  Evolution of species as a class diagram Among, all the animals, humans are capable of quite peculiar and advanced abilities that come with the large brain and cognitive development. Humans have developed so advance with our capabilities we have complex languag...

Linux deleted log file doesn't free up the disk space

TL DR; Kill or restart the process which writes the log file. Even though the file is deleted, it won't free up the disk space if the process is still writing to the log file. Only after stopping the process, it will actually be deleted. ---------------------------------------------------------------------------------------- Usually, disk spaces of servers are getting cluttered and filled by application log files when a proper log rotation mechanism is not implemented.  In case if you find such a log file causing the disk space to fill up 100%, it will probably impact any application which trying to use the disk.  You can see the disk space by the following command. df -h If the root dir ("/") usage is 100% the impact may be high for the system. Or else, if there is more than one disk attached then any application that uses that disk can be impacted.  In the above image, mine is not filled yet. I have only used 25% of the disk. How to find what files are using the disk sp...