自由學習的風

幽夢影 張潮 少年讀書,如隙中窺月;中年讀書,如庭中望月;老年讀書,如臺上玩月。皆以閱歷之淺深,為所得之淺深耳。

轉:DOCKER – HOW TO CONNECT TO A MYSQL RUNNING CONTAINER

2019年6月15日 星期六


轉貼自 LITTLETECHBLOGGER
---------------------------------
1. What we want to achieve:
We used the official mysql image from Docker Hub (https://hub.docker.com/_/mysql/), and created a running database container.
Now we need to connect to the MySQL database using MySQL command line client, to do some database operation.

2. Solution1:
Bash into the running container and run MySQL client.
2.1 Bash into the running MySQL container:
$ docker exec -t -i <container_name> /bin/bash
2.2 Run MySQL client:
$ mysql -u “<useranme>” -p

3. Solution2:
Use MySQl Command Line Client.
In the official guide, it states:
The following command starts another mysql container instance and runs the mysql command line client against your original mysql container, allowing you to execute SQL statements against your database instance:
$ docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
The variables here are really confusing.  Here is a more readable version of this command:
$ docker run -it --link <container_name>:<image_name> --rm <image_name> sh -c 'exec mysql -h"<container_ip_address>" -P"<mysql_port_number>" -u"<mysql_username>" -p"<mysql_password>"'
Now, lets use an example to explain how to find all the variables.

3.1 Get container_name, image_name, mysql_port_number:
$ docker ps
1
We can get:
container_name: romuiweb_db_1
image_name: mysql
container_port_number: 3306

3.2 Get container_ip_address:
$ docker inspect –format ‘{{ .NetworkSettings.IPAddress }}’ <container_id>
1

3.3 Get mysql_username, mysql_password:
When we start the mysql image, we set environment variables to decide the username and password.
username is default to root.
password is set by MYSQL_ROOT_PASSWORD, and we can find it in docker-compose.yml file:
1
So we can get:
mysql_username: root,
mysql_password: password.

3.4 Create the real command:
Now we have all the values of the variables. We can construct the real command:
$ docker run -it –link romuiweb_db_1:mysql –rm mysql sh -c ‘exec mysql -h”172.17.0.2″ -P”3306″ -u”root” -p”password”‘

3.5 Run the command, gain access to MySQL:
1

If it works, skip the following problem solving part.

3.6 Problem Solving:
(In this problem, we are not using romuiweb_db_1 we used earlier. We switch to docker_db_1. The Ip Address is different now)
docker: Error reponse from daemon: Cannot link to <container_name>, as it does not belong to the default work.
$ docker run -it –link docker_db_1:mysql –rm mysql sh -c ‘exec mysql -h”172.20.0.3″ -P”3306″ -u”root” -p”password”‘
1
This means that we are not running the mysql connect container on the same network the mysql container is currently running on. We need to connect it to the same network use –net option. Reference: https://docs.docker.com/engine/userguide/containers/networkingcontainers/
Step1: Find out which network mysql container is running on:
$ docker inspect docker_db_1
Find the “Networks”:
1
As we can see from the screenshot above, the network docker_db_1 is running on is “docker_default”. We need to connect to this network. So we change out command to this:
$ docker run -it –net=docker_default –link docker_db_1:mysql –rm mysql sh -c ‘exec mysql -h”172.20.0.3″ -P”3306″ -u”root” -p”password”‘
After adding the network argument, we successfully connected:
1

[Git] 在命令提示字元視窗下,中文亂碼的解決方式

2019年6月7日 星期五

解決當前使用的視窗中文亂碼的設定方式:
git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
set LESSCHARSET=utf-8

永久正常顯示中文的方式,只要把最後一列的環境變數加到Windows 的系統環境變數即可。

[網路教學]Vue教學文章或影片

2019年5月11日 星期六



[轉][程式] Postman - 測試Web Service的工具

2019年5月6日 星期一

原文: Postman - 測試Web Service的工具

 Postman 是用來測試 Web Service 方便的工具,在法蘭克還不認識它之前,要測試自己撰寫的 Web Service 都要用 HTML 刻一個表單,然後放上許多 input 的元件並且一個一個填入參數去 Call API,過程可說是相當麻煩,但是自從知道 Postman 後,就再也沒有自己刻過表單了。Postman 是 Chrome 的應用程式並可在 Chrome Web 商店找到它。今天就來介紹利用 Postman(Client端) 呼叫 TOS - ESB (Server端) 的一些基本功能並找兩個範例來實作,當然 Server 並非一定要跟法蘭克一樣是使用 TOS - ESB,也可是政府開放平台或公司後台的 API。

轉:建立安全的登入模組

2019年5月5日 星期日

原文:https://en.wikibooks.org/wiki/PHP_Programming/Building_a_secure_user_login_system

關鍵點:
$timeout = 60 * 30; // In seconds, i.e. 30 minutes.
$fingerprint = hash_hmac('sha256', $_SERVER['HTTP_USER_AGENT'], hash('sha256', $_SERVER['REMOTE_ADDR'], true));
session_start();
if (    (isset($_SESSION['last_active']) && $_SESSION['last_active']<(time()-$timeout))
     || (isset($_SESSION['fingerprint']) && $_SESSION['fingerprint']!=$fingerprint)
     || isset($_GET['logout'])
    )
{
    setcookie(session_name(), '', time()-3600, '/');
    session_destroy();
}
session_regenerate_id(); 
$_SESSION['last_active'] = time();
$_SESSION['fingerprint'] = $fingerprint;
// User authenticated at this point (i.e. $_SESSION['email_address'] can be trusted).

轉: How to enable and start services on Alpine Linux

2019年5月4日 星期六

Alpine Linux 是個小巧輕量的 Linux系統,非常值得試試

原文:https://www.cyberciti.biz/faq/how-to-enable-and-start-services-on-alpine-linux/


How do I add or delete service at boot time on an Alpine Linux? How do I enable service such as Nginx/Apache at boot time on an Alpine Linux? How do I start/stop/restart services on an Alpine Linux?
Alpine Linux comes with OpenRC init system. This tutorial shows how to use the various command on OpenRC to manage services.View status of all services
Type the following command:# rc-status