March 17, 2020

Connect to public hosted Ubuntu server MySQL Docker Image from local MySQL Workbench

Hi folks,

Today I am going to explain the procedure to test the public cloud hosted MySQL docker in Ubuntu Server to your local MySQL WorkBench.

We configured a Ubuntu Server on public cloud and installed docker.
Ping the public IP address to make sure, it is reachable to your pc/laptop.

Configure System

Install MySQL Docker Image

# docker pull mysql/mysql-server:latest

Check the images

#docker images
You should be able to view the downloaded mysql server image

Start the MySQL Server

# docker run --name=mysql1 -p 33061:3306 -d mysql/mysql-server
-d : Run in daemon mode
-p host_port:container_port
--name: container name
The mapped public ubuntu server port is 33061, which is mapped to the mysql server port 3306.

Check the containers

# docker ps
You should be able to view your mysql docker containers with container id and ports information

Get the MySQL root user password

MySQL generates a one-time password for docker container and writes to the log.

  • To view the log, execute the following command

# docker logs mysql1

  • To get the generate one-time password, filter the log with keyworkd "GENERATED"

# docker logs mysql1 2>&1 | grep GENERATED

  • You should be able to get the line like below

GENERATED ROOT PASSWORD: Axegh3kAJyDLaRuBemecis&EShOs

  • Copy the one-time password. In the next step, we will use this to login.

Reset MySQL root user password


  • Connect to MySQL server

# docker exec -it mysql1 -uroot -p

  • Paste the generated root password
  • Change the password

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpwd';
mysql> FLUSH PRIVILEGES;
  • Though you have the root user credentials, you won't be able to connect.
Root cause: root user belongs to localhost, not for the public host usage
Solution: create another user with all privileges
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'youpwd';
mysql> GRANT ALL PRIVILEGES on *.* TO USER 'username'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

  • Exit the mysql

mysql> exit;

  • Restart the docker

# docker restart mysql1

Connect from MySQL Workbench


  1. Open MySQL Workbench
  2. Click on add new connection icon
  3. Enter the "Connection name"
  4. Enter host name "public IP address" or "URL"
  5. Enter username as "dev" (Above created user)
  6. Click on Password "Store in vault" button and enter the "dev" user password
  7. Click on "Test Connection" button
  8. You should be able to view the "Successfully made the SQL Connection" pop-up


Hope this tutorial helps you to get connected with your public hosted mysql docker instance to your local mysql workbench.

Please send your feedback and comments to psrdotcom@gmail.com

March 06, 2020

View docker image file content with folder structure

Hi folks,

I have come across a scenario where I need to see the image contents.

Yes, I want to view the image content with hierarchy.

Then I found this dive, which has done it beautifully.

Install on Ubuntu PC


  1. # wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.deb
  2. # sudo apt install ./dive_0.9.2_linux_amd64.deb

Usage


  • Get the docker images list
    • # docker image list
  • Choose the image which you want to explore by copying the "Repository" name
  • Run the command
    • # dive
  • It takes some time to analyse and display the image contents in hierarchical manner.
  • Of the left side, it will have the image layers
  • Select the appropriate image layer with up/down arrow keys
  • By pressing the "Tab" you will be able to switch to right side view where your files are available
  • Use space to expand/collapse the folder
  • Dive will display each folder size
  • See the sample docker image contents with dive below




  • To quit/exit from the dive, use Ctrl+C


Hope this is helpful

Please send your feedback and comments to psrdotcom@gmail.com

March 03, 2020

Run local file server with NPM http-server

Hi folks,

Today i'll explian the process of making your folder as a standalone file server.

Objective

Make my folder contents browse over http

Procedure


  • Install Node
  • Install http-server module in node globally
    • npm install -g http-server
  • Open terminal/command-prompt
  • Navigate to your folder
  • Run the following command to start the server
    • http-server .
  • or simply run
    • hs .
  • Run from anywhere with full path of the folder
    • hs C:\FileFolder
  • Starting up http-server, serving .
  • Available on:
    • http://10.10.6.2:8080
    • http://127.0.0.1:8080
    • http://youripaddress:8080
  • Hit CTRL-C to stop the server
  • You should be able to browse your file folder contents with any of the above URLs
Hope you are able to access your file contents over the browser

Tip: Using this approach, you can share your content over intranet/internet with full control over data as read only.

After stopped the server, access to the folder is stopped.

Please send your comments and feedback to psrdotcom@gmail.com

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com