<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stan Liu on Medium]]></title>
        <description><![CDATA[Stories by Stan Liu on Medium]]></description>
        <link>https://medium.com/@stan5566?source=rss-480c3aeb0070------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rAe-5G1hXg0b0RrcfNPWyA.png</url>
            <title>Stories by Stan Liu on Medium</title>
            <link>https://medium.com/@stan5566?source=rss-480c3aeb0070------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:05:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stan5566/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[如何備份iPhone到外接硬碟？]]></title>
            <link>https://medium.com/@stan5566/%E5%A6%82%E4%BD%95%E5%82%99%E4%BB%BDiphone%E5%88%B0%E5%A4%96%E6%8E%A5%E7%A1%AC%E7%A2%9F-c7a367ff0613?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7a367ff0613</guid>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Sat, 13 Jun 2020 05:49:44 GMT</pubDate>
            <atom:updated>2020-07-04T03:22:29.724Z</atom:updated>
            <content:encoded><![CDATA[<p>首先要知道iPhone備份在哪</p><pre>~/Library/Application Support/MobileSync/Backup</pre><p>接著在Mac Finder裡面按快捷鍵 cmd + shift + G 或是上面點選 <strong>前往</strong> -&gt; <strong>前往資料夾</strong>，這時候會跳出一個視窗，貼上上面的位址，就會進到iPhone備份的資料夾裡。</p><p>接著把Backup這個資料夾複製貼上到外接硬碟裡，這邊假設貼在一個外接硬碟名稱叫做<strong>1TB</strong>，所以資料夾位址會是這樣</p><pre>/Volumes/1TB/Backup</pre><p>然後把原本的備份資料夾<strong>Backup</strong>刪除。</p><p><strong>注意：這邊一定要確定有複製過去才能刪除哦。</strong></p><p>接著用建立超連結的方式，在MobileSync資料夾裡建立一個外接硬碟裡Backup資料夾的超連結，macOS稱作<strong>symlink</strong>。</p><p>打開<strong>Terminal</strong>或稱<strong>終端機</strong>，輸入下面的指令</p><pre># ln -s               // 建立一個symlink<br># /Volumes/1TB/Backup // 從來源資料夾<br># /Users/你的使用者名稱/Library/Application Support/MobileSync/Backup // 到目標資料夾</pre><pre>ln -s /Volumes/1TB/Backup /Users/你的使用者名稱/Library/Application Support/MobileSync/Backup</pre><blockquote>注意，symlink只能使用檔案的絕對位址</blockquote><p>檢查一下是否有成功</p><pre>~/Library/Application Support/MobileSync/</pre><p>進到上方位址看<strong>Backup</strong>資料夾的左下角是不是多了一個箭頭的符號，左鍵點兩下進入資料夾裡面看是不是實際到了外接硬碟裡的<strong>Backup</strong>資料夾裡</p><p>這樣就成功的把原本備份在Mac硬碟裡的資料夾，移到了外接硬碟</p><p>Click backup button!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7a367ff0613" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker (2) Startup script]]></title>
            <link>https://medium.com/@stan5566/docker-2-startup-script-febaeea29be?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/febaeea29be</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Sat, 13 Jan 2018 17:37:31 GMT</pubDate>
            <atom:updated>2018-01-13T17:37:31.823Z</atom:updated>
            <content:encoded><![CDATA[<p>Face the problem where should I put Django migrate, cron service command as long as web service started.</p><p>docker-compose.yml</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  nginx:<br>    restart: always<br>    container_name: ng01<br>    build: ./nginx/<br>    ports:- &#39;8080:80&#39;<br>    volumes:<br>      - web_data:/web_data<br>      - ./log:/var/log/nginx</pre><pre>redis:<br>    restart: always<br>    container_name: rd01<br>    image: redis:3.0<br>    expose:<br>      - &#39;6379&#39;</pre><pre>web:<br>    restart: always<br>    container_name: wb01<br>    build: ./web/<br>    links:<br>      - postgres:postgres<br>      - redis:redis<br>      - nginx:nginx<br>    env_file: env<br>    #environment:<br>    #  DEBUG: &#39;true&#39;<br>    command: ./docker-entrypoint-initservice.d/docker-entrypoint.sh<br>    volumes:<br>      - web_data:/web_data<br>    expose:<br>      - &#39;8000&#39;<br>    depends_on:<br>      - postgres</pre><pre>postgres:<br>    restart: always<br>    container_name: pg01<br>    image: postgres<br>    volumes:<br>      - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d<br>      - pg_data:/var/lib/postgresql/data<br>      - pg_data:/var/lib/postgresql/backups<br>    env_file:<br>      - env<br>    expose:<br>      - &#39;5432&#39;</pre><pre>data:<br>    restart: always<br>    container_name: data01<br>    image: alpine<br>    volumes:<br>      - pg_data:/var/lib/postgresql/data<br>    #command: &quot;true&quot;<br>    stdin_open: true # corresponds to -i<br>    tty: true # corresponds to -t</pre><pre>volumes:<br>  web_data:<br>  pg_data:</pre><p>The beginning docker-entrypoint-initservice.d/docker-entrypoint.sh</p><pre>#!/bin/sh</pre><pre>##### Python</pre><pre># migration<br>echo &quot;Python migrating...&quot;<br>python manage.py makemigrations;<br>python manage.py migrate;<br>python manage.py collectstatic --noinput; # --noiput to skip collectstatic confirmation</pre><pre>##### cron</pre><pre># add a scheduled task for cron<br>echo &quot;add schedule task for cron&quot;<br>crontab /etc/cron.d/crawl-task;</pre><pre># start cron<br>echo &quot;cron starting&quot;<br>service cron start;</pre><p>First, I try CMD [&quot;/docker-entrypoint-initservice.d/docker-entrypoint.sh&quot;] but the intermediate container will be removed after execution.</p><p>Second, I try ENTRYPOINT [&quot;/docker-entrypoint-initservice.d/docker-entrypoint.sh&quot;] but web service exited at code 0 after execution.</p><p>Third, change docker-compose.yml service: command: bash -c &quot;/docker-entry-initservice.d/docker-entrypoint.sh &amp;&amp; uwsgi --ini uwsgi.ini . FIrst time I think exited at code 0 bebcause postgres db is not ready yet. I put a sleep 5 to wait for db ready. But same exited at code 0 after excution like the second one…</p><p>In the end, I change service command command: /docker-entry-initservice.d/docker-entrypoint.sh and mydocker-entrypoint.sh like below. Although sleep 5 is not a good solution. At lease now works…</p><p><strong>Edited docker-entrypoint-initservice.d/docker-entrypoint.sh</strong></p><pre>#!/bin/sh</pre><pre>sleep 5 # wait for db </pre><pre>##### Python</pre><pre># migration<br>echo &quot;Python migrating...&quot;<br>python manage.py makemigrations;<br>python manage.py migrate;<br>python manage.py collectstatic --noinput; # --noiput to skip collectstatic confirmation</pre><pre>##### cron</pre><pre># add a scheduled task for cron<br>echo &quot;add schedule task for cron&quot;<br>crontab /etc/cron.d/crawl-task;</pre><pre># start cron<br>echo &quot;cron starting&quot;<br>service cron start;</pre><pre>sleep 1</pre><pre># start uWSGI<br>echo &quot;uWSGI starting&quot;<br>uwsgi --ini uwsgi.ini</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=febaeea29be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nginx & uWSGI]]></title>
            <link>https://medium.com/@stan5566/nginx-uwsgi-977d551497d0?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/977d551497d0</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[uwsgi]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Thu, 11 Jan 2018 12:20:27 GMT</pubDate>
            <atom:updated>2018-01-11T12:20:27.165Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Setting up Django and your web server with uWSGI and nginx</blockquote><p><a href="https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html">From official uWSGI tutorial</a></p><blockquote>Warning From official uWSGI tutorial: use Django 1.4</blockquote><h4>Concept</h4><p>Feed it requests from web clients and go through the socket, uwsgi to Django application returns response then reverse to the client.</p><pre>the web client &lt;-&gt; the web server &lt;-&gt; the socket &lt;-&gt; uwsgi &lt;-&gt; Django</pre><p>Add a line in default nginx, shown as bold below:</p><pre>user  root;<br>worker_processes  1;</pre><pre>error_log  /var/log/nginx/error.log warn;<br>pid        /var/run/nginx.pid;</pre><pre>events {<br>    worker_connections  1024;<br>}</pre><pre>http {<br>    include       /etc/nginx/mime.types;<br>    default_type  application/octet-stream;<br>    log_format  main  &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;<br>    &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;<br>    &#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;;</pre><pre>    access_log  /var/log/nginx/access.log  main;<br>    sendfile        on;</pre><pre>    #tcp_nopush     on;<br>    keepalive_timeout  65;</pre><pre>    #gzip  on;</pre><pre>    # include /etc/nginx/conf.d/*.conf;<br>    <strong>include /etc/nginx/sites-enabled/*;</strong><br>}</pre><ol><li>Copy my <strong>nginx.conf</strong> for replacing default nginx.conf</li><li>Copy local <strong>sites-available</strong> folder into nginx folder</li></ol><pre>├── nginx                                                                                                                                           <br>│   ├── Dockerfile <br>│   ├── nginx.conf <strong><em># 1 custom nginx.conf but same name</em></strong><br>│   └── sites-available <strong><em># 2</em></strong>                                                                                                                              <br>│       └── django.conf</pre><p>3. create <strong>sites-enabled </strong>folder and link <strong>*.conf</strong> from <strong>sites-available</strong> to <strong>sites-enabled</strong></p><blockquote><strong>Nginx should has these two folder </strong><strong><em>sites-available and </em></strong><strong><em>sites-enabled . You will have its if you install nginx using </em></strong><strong><em>apt-get</em>. But here we’re using docker image, its need to be created by our own.</strong></blockquote><pre>FROM nginx:latest</pre><pre>COPY nginx.conf /etc/nginx/nginx.conf <strong><em># 1</em></strong><br>COPY sites-available /etc/nginx/sites-available/ <strong><em># 2</em></strong></pre><pre># 3<br>RUN mkdir -p /etc/nginx/sites-enabled/\<br>  &amp;&amp; ln -s /etc/nginx/sites-available/*.conf /etc/nginx/sites-enabled/</pre><pre>CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]</pre><p>nginx -T 查詢現在所有的 nginx configurations</p><pre>$ <strong>nginx -T</strong><br>&gt;<br>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful<br># configuration file /etc/nginx/nginx.conf:<br>user  root;<br>worker_processes  1;</pre><pre>error_log  /var/log/nginx/error.log warn;<br>pid        /var/run/nginx.pid;</pre><pre>events {<br>    worker_connections  1024;<br>}</pre><pre>http {<br>    include       /etc/nginx/mime.types;<br>    default_type  application/octet-stream;<br>    log_format  main  &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;<br>                      &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;<br>                      &#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;;</pre><pre>access_log  /var/log/nginx/access.log  main;</pre><pre>sendfile        on;<br>    #tcp_nopush     on;</pre><pre>keepalive_timeout  65;</pre><pre>#gzip  on;</pre><pre># include /etc/nginx/conf.d/*.conf;<br>    <strong>include /etc/nginx/sites-enabled/*;</strong><br>}<br># configuration file /etc/nginx/mime.types:</pre><pre>types {<br>    ...<br>}</pre><pre><strong># configuration file /etc/nginx/sites-available/my_nginx.conf:</strong></pre><pre># the upstream component nginx needs to connect to<br>upstream uwsgi {<br>    # server api:8001; # use TCP<br>    server unix:/docker_api/app.sock; # for a file socket<br>}</pre><pre># configuration of the server<br>server {<br>    # the port your site will be served on<br>    listen    81;<br>    # index  index.html;<br>    # the domain name it will serve for<br>    # substitute your machine&#39;s IP address or FQDN<br>    server_name  twtrubiks.com <a href="http://www.twtrubiks.com/">www.twtrubiks.com</a>;<br>    charset     utf-8;</pre><pre>client_max_body_size 75M;   # adjust to taste</pre><pre># Django media<br>    # location /media  {<br>    #     alias /docker_api/static/media;  # your Django project&#39;s media files - amend as required<br>    # }</pre><pre>location /static {<br>        alias /docker_api/static; # your Django project&#39;s static files - amend as required<br>    }</pre><pre>location / {<br>        uwsgi_pass  uwsgi;<br>        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed<br>    }</pre><pre>}</pre><pre># configuration file /etc/nginx/uwsgi_params:</pre><pre>uwsgi_param  QUERY_STRING       $query_string;<br>uwsgi_param  REQUEST_METHOD     $request_method;<br>uwsgi_param  CONTENT_TYPE       $content_type;<br>uwsgi_param  CONTENT_LENGTH     $content_length;</pre><pre>uwsgi_param  REQUEST_URI        $request_uri;<br>uwsgi_param  PATH_INFO          $document_uri;<br>uwsgi_param  DOCUMENT_ROOT      $document_root;<br>uwsgi_param  SERVER_PROTOCOL    $server_protocol;<br>uwsgi_param  REQUEST_SCHEME     $scheme;<br>uwsgi_param  HTTPS              $https if_not_empty;</pre><pre>uwsgi_param  REMOTE_ADDR        $remote_addr;<br>uwsgi_param  REMOTE_PORT        $remote_port;<br>uwsgi_param  SERVER_PORT        $server_port;<br>uwsgi_param  SERVER_NAME        $server_name;</pre><blockquote>conf.d does the job but you have to move something out of the folder, delete it, or make changes to it when you need to disable something.</blockquote><blockquote>sites-available is for storing <strong>all of your vhost configuration</strong>, whether or not they&#39;er currently enabled.</blockquote><blockquote>sites-enabled contains symlinks to files in the sites-available folder. This <strong>allows you to selectively disable vhosts by removing the symlink.</strong></blockquote><blockquote>The sites-* folder abstraction makes things <strong>more organized</strong> and <strong>allows you to manage</strong> them with separate support scripts.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=977d551497d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[docker-compose 3 Postgresql learning note]]></title>
            <link>https://medium.com/@stan5566/docker-compose-3-postgresql-learning-note-7a929040cd98?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a929040cd98</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Wed, 10 Jan 2018 09:43:09 GMT</pubDate>
            <atom:updated>2018-01-11T02:07:25.720Z</atom:updated>
            <content:encoded><![CDATA[<p>postgres and volumes</p><p>my folder tree</p><pre>├── postgres<br>│   └── docker-entrypoint-initdb.d<br>│       └── my_initdb.sh</pre><p>docker-compose.yml</p><pre>services:<br>  postgres:<br>    image: postgres<br>    #entrypoint: ./postgres/docker-entrypoint-initdb.d/curr_web.sh<br>    volumes:<br>      <em># map local docker-entrypoint to container</em><br>      - ./postgres/docker-entrypoint-initdb.d:docker-entrypoint-initdb.d</pre><pre>      <em># postgres&#39; data, could used fo backup</em><br>      - pg_data:/var/lib/postgresql/data<br>      - pg_data:/var/lib/postgresql/backups</pre><pre>    expose:<br>      - &#39;5432&#39;</pre><pre>volumes:<br>  pg_data:</pre><h4><strong>Postgresql exec docker-entrypoint-initdb.d</strong></h4><pre>volumes:<br>  - ./path/to/my/host/folder:/docker-entrypoint-initdb.d/</pre><blockquote>references: <a href="https://gist.github.com/onjin/2dd3cc52ef79069de1faa2dfd456c945">https://gist.github.com/onjin/2dd3cc52ef79069de1faa2dfd456c945</a></blockquote><p>My docker-compose.yml</p><pre>volumes:<br>  <em># map local docker-entrypoint to container<br>  </em>- .docker-entrypoint-initdb.d:docker-entrypoint-initdb.d</pre><p>My init_db.sh to create Database PASSWORD and USER</p><pre>#!/bin/sh<br>psql -U postgres -c &quot;CREATE USER $DB_USER PASSWORD &#39;$DB_PASS&#39;&quot;<br>psql -U postgres -c &quot;CREATE DATABASE $DB_NAME OWNER &#39;$DB_USER&#39;&quot;</pre><p>docker-compose <strong>up</strong> <strong>build</strong></p><pre>$ docker-compose up --build</pre><pre>&gt;<br>...<br>2018-01-10T09:46:05.572854165Z<br>/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/my_initdb.sh<br>CREATE ROLE<br>CREATE DATABASE<br>...</pre><h4>Postgresql File System Level Backup</h4><p>Postgresql Data path by <a href="https://www.postgresql.org/docs/9.3/static/backup-file.html">Official tutorial from PostgreSQL documentation</a></p><pre>/usr/local/pgsql/data</pre><pre># to archive data<br>$ tar -cf backup.tar /usr/local/pgsql/data</pre><p>But using container for running postgresql, data path is like below (maybe just because different os, not sure)</p><pre>/var/lib/postgresql/data</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a929040cd98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WSGI 學習筆記]]></title>
            <link>https://medium.com/@stan5566/wsgi-%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-a29b5c925eae?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/a29b5c925eae</guid>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Tue, 09 Jan 2018 13:04:15 GMT</pubDate>
            <atom:updated>2018-01-09T14:05:32.473Z</atom:updated>
            <content:encoded><![CDATA[<p>Using python, pyenv to practicce wsgi</p><h3>Pyenv activate a env</h3><pre>$ pyenv virtualenv 3.5.0 wsgi_env</pre><pre>$ pyenv local wsgi_env</pre><pre>$ python -V<br>&gt; Python 3.5.0</pre><h3>Install</h3><pre>$ pip install uwsgi</pre><p>The First WSGI application</p><pre>$ cat footer.py</pre><pre>&gt; <strong>def</strong> <strong>application</strong>(env, start_response):<br>    start_response(&#39;200 OK&#39;, [(&#39;Content-Type&#39;,&#39;text/html&#39;)])<br>    <strong>return</strong> [b&quot;Hello World&quot;]</pre><p>Deploy it on HTTP port 9090</p><pre>$ uwsgi --http :9090 --wsgi-file foobar.py</pre><pre>$ curl localhost:9090<br>&gt; Hello World%</pre><h4>Adding concurrency and monitoring</h4><pre>$ uwsgi --http :9090 --wsgi-file footer.py --master --processes 4 --thread 2 --stats 127.0.0.1:9191</pre><p><strong>Using </strong><a href="https://github.com/xrmx/uwsgitop"><strong>uwsgitop</strong></a><strong> to monitor uwsgi server</strong></p><p>To use uWSGI Stat Server simply use the stats option followed by a valid socket address, for example:</p><pre>uwsgi --module myapp --socket :3030 --stats /tmp/stats.socket</pre><p>To start monitoring your application with uwsgitop call it with the socket address like so:</p><pre>uwsgitop /tmp/stats.socket</pre><p>If you want the stats served over HTTP you will need to add the stats-http option in uWSGI:</p><pre>uwsgi --module myapp --http :3030 --stats :3031 --stats-http</pre><p>You’ll now need to call uwsgitop as:</p><pre>uwsgitop <a href="http://127.0.0.1:3031/">http://127.0.0.1:3031</a></pre><h4>Putting behind a full webserver</h4><p>A common nginx config is the following:</p><pre>location / {<br>  include uwsgi_params;<br>  uwsgi_pass 127.0.0.1:3031<br>}</pre><p>This means “pass every request to the server bound to port 3031 speaking the uwsgi protocol”</p><p>Now we can spawn uWSGI to natively speak the uwsgi protocol</p><pre>$ uwsgi --socket 127.0.0.1:3031 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191</pre><p>run ps aux | grepwill see one process less.</p><blockquote>If your proxy/webserver/router speaks HTTP, you have to tell uWSGI to natively speak the http protocol (this is different from –http that will spawn a proxy by itself):</blockquote><h3>Deploying Django</h3><p>Let’s using command</p><pre>$ uwsgi --socket 127.0.0.1:3031 --chdir home/code/backend/WSGI/wsgi_example --wsgi-file wsgi_example/wsgi.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191</pre><p>WSGI/wsgi_example is directory of a django project</p><pre>$ tree<br>&gt;.<br> ├── nginx.conf<br> ├── wsgi_example # under WSGI folder<br> │   ├── app<br> │   ├── manage.py<br> │   └── wsgi_example # --wsgi-file wsgi_example/wsgi.py<br> │       ├── settings.py<br> │       ├── urls.py<br> │       └── wsgi.py<br> └── my_wsgi.ini</pre><p>Using .ini file to get rid of tedious command</p><pre># my_wsgi.ini</pre><pre><strong>[uwsgi]</strong><br>socket <strong>=</strong> 127.0.0.1:3031<br>chdir <strong>=</strong> /home/code/backend/WSGI/wsgi_example<br>wsgi-file <strong>=</strong> wsgi_example/wsgi.py<br>processes <strong>=</strong> 4<br>threads <strong>=</strong> 2<br>stats <strong>=</strong> 127.0.0.1:9191</pre><p>If you’re using old (&lt; 1.4) Django. See blow #<a href="https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#deploying-django">deploying Django</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a29b5c925eae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nginx 學習筆記]]></title>
            <link>https://medium.com/@stan5566/nginx-%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-850147a74745?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/850147a74745</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Tue, 09 Jan 2018 08:28:25 GMT</pubDate>
            <atom:updated>2018-01-17T09:51:06.960Z</atom:updated>
            <content:encoded><![CDATA[<h3>簡介</h3><p>用來處理 server 中靜態的內容</p><h3>Install</h3><pre>$ brew install nginx</pre><h3>Run</h3><pre># start nginx<br>$ nginx</pre><pre># -s to using parameter<br>$ nginx -s stop # stop nginx</pre><pre>$ nginx -s reload # reload nginx configurations</pre><pre># OR</pre><pre>$ brew services start nginx<br># run nginx service in background services, if you don&#39;t want/need a backgound service you can just run: nginx</pre><blockquote>warning: 如果用 brew 啟動 nginx，就不能再使用 -s帶入參數，因為跟 nginx 內建的路徑不同。</blockquote><blockquote>[error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)</blockquote><blockquote>使用nginx啟動服務，他的路徑是/usr/local/var/run/nginx.pid</blockquote><blockquote>但使用brew，brew 會把一個 service 用 plist 的方式加到 /Library/LaunchAgents</blockquote><blockquote>e.g. /Library/LaunchAgents/homwbrew.mxcl.nginx.plist</blockquote><blockquote>可使用 brew services list — verbose 查看</blockquote><p>references: <a href="https://robots.thoughtbot.com/starting-and-stopping-background-services-with-homebrew">Starting and Stopping Background Services with Homebrew</a></p><h3>Test</h3><p>打開你的瀏覽器並輸入localhost:8080 就會看到nginx的歡迎畫面</p><h4>nginx.conf</h4><p>configuration of nginx, 會依據安裝方式導致被放置的路徑不同，可以透過nginx -t 來查詢</p><pre>$ nginx -t<br>&gt; nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok<br>&gt; nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful</pre><p>config是由一連串的directive所組成，又分為: <strong>simple directive</strong>, <strong>block directive</strong></p><p>simple directive 一定要以分號;結尾</p><pre>location {<br>  root /data; # simple directive<br>}</pre><p>block directive 則是使用一組大括號<strong> </strong>{}<strong> </strong>包起來</p><pre>http {<br>  server {<br>    location {}<br>  }<br>}</pre><p>http, server, location 都是屬於block directive，並有著從屬關係</p><blockquote>location block 一定要在 server block裡面，server block 一定要在 http block裡面。</blockquote><blockquote>最底層的block只有兩種：http, event，called “main context”</blockquote><h3>Serving Static Content</h3><p>主要用來處理像是圖片等檔案或是的靜態網頁，這邊實作<a href="http://nginx.org/en/docs/beginners_guide.html">官方</a>的教學。</p><p>根據不同請求，檔案從不同的本地路徑中被處理: /data/www (html)，/data/images(圖片)，定義一個 server block 在 http block裡面。</p><p>首先，建立一個 /data/www 路徑，把 index.html檔案放進去，接著建立 data/images，並放幾張圖片進去。</p><p>接著來建立 nginx.conf，我把它命名為 my_nginx.conf，在下面dockerfile會把這個檔案 copy 進去 nginx docker container</p><pre>http {<br>  server {<br>    location / { # the shortest prefix<br>      root /data/www;<br>    }</pre><pre>    location /images/ { # match requests which start with /images/<br>     root /data;<br>    }<br>  }  <br>}</pre><p>the “/” prefix 會跟請求的URI比較，為了要對應到請求，URI會被指定給root directive，就是 data/www。如果有很多對應到 location block，nginx會選擇最長的prefix。location / { }這是最短的prefix，全部都找不到的時候才會最後被使用。</p><h3>Nginx Docker</h3><p>這邊我使用 docker 來實作 nginx 範例，下面是我的 <strong>Dockerfile</strong></p><pre>FROM nginx:latest</pre><pre># copy my custom configuration file to nginx default conf<br>COPY my_nginx.conf /etc/nginx/nginx.conf</pre><pre># copy static data directory we created above from official tutorial<br>COPY data data</pre><p>先 <strong>build</strong> docker，幫 image 取一個名字 nginx-example:1.3 這邊我用<strong> 1.3</strong> 來區隔我之前測試失敗的image版號</p><pre>$ docker build -t nginx-example:1.3 .</pre><p>接著 <strong>run</strong> docker</p><pre>$ docker run --name nginx-example -d -p 8080:80 nginx-example:1.3</pre><pre>$ docker ps<br># 可以看到container 的id, image, status, port, names</pre><pre>&gt; CONTAINER ID        IMAGE               COMMAND                  CREATED                  STATUS              PORTS                  NAMES<br>958cd59dcc7f        nginx_example:1.3   &quot;nginx -g &#39;daemon ...&quot;   Less than a second ago   Up 2 seconds        0.0.0.0:8080-&gt;80/tcp   nginx-example</pre><blockquote>注意：因為上面的 my_nginx.conf 沒有定義監聽的 port，所以預設就是 80。</blockquote><blockquote>docker run ... -p 8080:80 is map host port 8080 to container port 80，所以在瀏覽器上輸入localhost:8080，然後因為 nginx listen 80 (container port)，</blockquote><blockquote>所以 nginx 就可以抓到從瀏覽器過來的request</blockquote><p>如果跟我一樣使用 docker，上面的 root /data 就是 $ docker exec -i -t bash 進去的跟目錄。就可以看到在 Dockerfile 裡面 COPY 進去的 <strong>data</strong> 資料夾(範例裡面叫我們建立的資料夾)</p><pre>root@:/ ls<br>&gt; bin boot <strong>data</strong> dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var</pre><p>接著在瀏覽器打</p><pre>localhost:8080/ # 顯示上面建立的 index.html</pre><pre>localhost:8080/images/1.JPG # 顯示放進去的圖片</pre><h3>Setting Up a Simple Proxy Server</h3><p>官方教學 again!</p><p>nginx 最常被拿來作為 proxy server， server app 透過某個 port 作為介面。</p><blockquote>server收到 requests 並把它傳給 proxied server，然後從 proxied server 得到 responses 傳回給 client。</blockquote><p>設定一個基本的 proxy server ，用來處理本地圖片的請求然後傳送所有請求到 proxied server。在這個範例會在一個 nginx 中定義兩個 services</p><p>首先，定義一個 server block，監聽 port 80，把所有請求對應到 /data/up1</p><p>接著，新增一個 index.html 進去/data/up1。</p><pre>server {<br>  listen 80;<br>  root /data/up1;</pre><pre>  location / {<br>  }<br>}</pre><p>再來，改變上面的 conf ，設定成 proxy server。</p><pre>server {<br>  listen 80;</pre><pre>  location / {<br>    # put proxy_pass directive with the protocol,<br>    # name of proxied server<br>    proxy_pass http://localhost:8080;<br>  }<br><br>  location /images/ {<br>   root /data;<br>  }<br>}</pre><p>接著修改第二個 location block。讓請求的URI /images/ prefix 對應到 /data/images路徑。</p><p>Server會把所有以 git, jpg, png 結尾的請求對應 /data/images 路徑 (by adding URI to the root directive&#39;s parameter)</p><pre>server {<br>  listen 80;</pre><pre>  location / {<br>    proxy_pass http://localhost:8080;<br>  }<br><br>  location ~* \.(gif|jpg|png)$ {<br>    root /data/images;<br>  }<br>}</pre><blockquote>“*” is used for case-insensitive, see <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location">location</a></blockquote><p>開啟 index.html</p><pre>localhost:8080</pre><p>開啟圖片</p><pre>localhost:8080/1.jpg</pre><p><a href="https://blog.toright.com/posts/3890/%E7%84%A1%E5%A0%85%E4%B8%8D%E6%91%A7%EF%BC%8C%E5%94%AF%E5%BF%AB%E4%B8%8D%E7%A0%B4%EF%BC%81%E5%BF%AB%E6%94%B9%E7%94%A8-nginx-php-fpm-%E5%8F%96%E4%BB%A3-apache-%E5%90%A7%EF%BC%81.html">無堅不摧，唯快不破！快改用 Nginx + PHP-FPM 取代 Apache 吧！ - Soul &amp; Shell Blog</a></p><h3>Reverse Proxy</h3><p>和常見的 Proxy server (代理伺服器)相反， reverse proxy server 負責將 client 端的資料傳給藏在 reverse proxy server 後面的 web server，這樣些在後面的 web server 不會也不能直接被用戶直接連結，只能經由 reverse proxy server 代理傳送和接收資料。</p><p>所以使用 reverse proxy server 可以保護後方的 web server 被攻擊。同時，還可以停供負載平衡 (Load Balance)、快取以及資料加密的功能。</p><h3>upstream module</h3><p>The <em>ngx_http_upstream_module</em> module is used to define groups of servers that can be referenced bytes the proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, and memcached_pass directives.</p><p>Example Configuration</p><pre>upstream <strong>backend</strong> {<br>  server backend1.example.com   weight=5;<br>  server backend2.example.com:8080;<br>  server unix:/tmp/backend3;</pre><pre>  server backup1.example.com:8080   backup;<br>  server backup2.example.com:8080   backup;<br>}</pre><pre>server {<br>  listen 80;</pre><pre>  location / {<br>    proxy_pass   <a href="http://backend;/">http://<strong>backend</strong>;</a><br>  }<br>}</pre><p>Dynamically configurable group with periodic health checks is available as part of our commercial subscription:</p><pre>resolver 10.0.0.1;<br><br>upstream <strong>dynamic</strong> {<br>    zone upstream_dynamic 64k;<br><br>    server backend1.example.com      weight=5;<br>    server backend2.example.com:8080 fail_timeout=5s slow_start=30s;<br>    server 192.0.2.1                 max_fails=3;<br>    server backend3.example.com      resolve;<br>    server backend4.example.com      service=http resolve;<br><br>    server backup1.example.com:8080  backup;<br>    server backup2.example.com:8080  backup;<br>}<br><br>server {<br>    location / {<br>        proxy_pass http://<strong>dynamic</strong>;<br>        health_check;<br>    }<br>}</pre><p><strong>Directives</strong></p><pre>Syntax:<strong>upstream</strong> <em>name</em> { ... }<br>Default:—<br>Context:http</pre><p>Defines a group of servers. Servers can listen on different ports. In addition, servers listening on TCP and UNIX-domain sockets can be mixed.</p><pre>upstream backend {<br>    server backend1.example.com <strong>weight=5</strong>; # 5 requests<br>    server 127.0.0.1:8080       max_fails=3 fail_timeout=30s;<br>    server unix:/tmp/backend3;<br><br>    server backup1.example.com  backup;<br>}</pre><p>By default, requests are distributed between the servers using a weighted round-robin balancing method. In the above example, each 7 requests will be distributed as follows: 5 requests go to backend1.example.com and one request to each of the second and third servers. If an error occurs during communication with a server, the request will be passed to the next server, and so on until all of the functioning servers will be tried. If a successful response could not be obtained from any of the servers, the client will receive the result of the communication with the last server.</p><pre>Syntax:<strong>server</strong> <em>address</em> [<em>parameters</em>];<br>Default:—<br>Context:upstream</pre><p>Defines the <em>address</em> and other <em>parameters</em> of a server. The address can be specified as a domain name or IP address, with an optional port, or as a UNIX-domain socket path specified after the “unix:” prefix. If a port is not specified, the port 80 is used. A domain name that resolves to several IP addresses defines multiple servers at once.</p><p>The following parameters can be defined:</p><p><strong>weight=</strong><strong><em>number</em></strong> sets the weight of the server, by default, 1.</p><p><strong>max_conns=</strong><strong><em>number</em></strong> limits the maximum <em>number</em> of simultaneous active connections to the proxied server (1.11.5). Default value is zero, meaning there is no limit. If the server group does not reside in the <a href="https://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone">shared memory</a>, the limitation works per each worker process.</p><p><strong>backup</strong> marks the server as a backup server. It will be passed requests when the primary servers are unavailable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=850147a74745" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redis 學習筆記]]></title>
            <link>https://medium.com/@stan5566/redis-%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-89fe82c53408?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/89fe82c53408</guid>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Tue, 09 Jan 2018 02:28:33 GMT</pubDate>
            <atom:updated>2018-01-09T08:30:06.870Z</atom:updated>
            <content:encoded><![CDATA[<h3>簡介</h3><p><a href="https://redis.io/">Redis</a> 是一個使用快取記憶體的key-value database，主要用來減輕後端資料庫的loading，由於速度優勢和使用方便，也是目前最熱門的key value cache工具。</p><h3>Install</h3><pre>$ brew install redis</pre><h3>Start Server</h3><pre># start server using redis default command<br>$ redis-server</pre><pre>OR</pre><pre># start server using brew services<br>$ brew services start redis</pre><h3>Test</h3><pre>$ redis-cli # enter redis shell<br>127.0.0.1:6379&gt; ping<br>&gt; pong</pre><h3>Configuration</h3><h4><strong>Show configurations</strong></h4><pre># input redis-cli to enter redis shell first<br>127.0.0.1:6379&gt; CONFIG GET * # get all the configurations of redis<br>&gt; &quot;dbfilename&quot;<br>&gt; &quot;dump.rdb&quot;<br>&gt; &quot;requirepass&quot;<br>&gt; ... .etcs</pre><h4>Edit</h4><pre># CONFIG SET &quot;key&quot; &quot;value&quot;<br>127.0.0.1:6379&gt; CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE</pre><h4>Example</h4><pre>127.0.0.1:6379&gt; CONFIG SET loglevel &quot;notice&quot;<br>&gt; OK<br>127.0.0.1:6379&gt; CONFIG GET loglevel<br>&gt; &quot;loglevel&quot;<br>&gt; &quot;notice&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89fe82c53408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 Docker 架設 Ruby on Rails & MongoDB 遇到的問題]]></title>
            <link>https://medium.com/@stan5566/%E4%BD%BF%E7%94%A8-docker-%E6%9E%B6%E8%A8%AD-ruby-on-rails-mongodb-%E9%81%87%E5%88%B0%E7%9A%84%E5%95%8F%E9%A1%8C-356312d54f89?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/356312d54f89</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Fri, 15 Dec 2017 17:20:35 GMT</pubDate>
            <atom:updated>2017-12-15T17:40:14.348Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>執行 docker-compose up啟動rails 跟 mongodb container 的時候，遇到 rails連不到 mongodb 的情況，把 docker-compose.yml的 <strong>db </strong>mapmongoid.yml就可以了。</li></ol><blockquote>docker-compose.yml</blockquote><pre>version: &#39;3&#39;<br>services:<br>  webapp:<br>    build: .<br>    command: bundle exec rails server --port 3000 --binding 0.0.0.0<br>    ports:<br>      - &quot;3001:3000&quot;<br>    links:<br>      - mongodb<br>    volumes:<br>      - .:/app<br>    depends_on:<br>      - mongodb</pre><pre>mongodb:<br>    image: mongo<br>    ports:<br>      - &quot;27017:27017&quot;</pre><blockquote>mongoid.yml</blockquote><pre>development:<br>  clients:<br>    default:<br>      database: development<br>      hosts:<br>        #- localhost:27017 # change here to `mongodb`<br>        - mongodb</pre><p>reference: <a href="https://stackoverflow.com/questions/40201069/not-able-to-connect-mongodb-with-rails-container-using-docker-compose">Not able to connect mongodb with Rails container using docker compose</a></p><p>reference: <a href="https://stackoverflow.com/questions/40075065/using-docker-i-get-the-error-sqlstatehy000-2002-no-such-file-or-directory">Using Docker I get the error: “SQLSTATE[HY000] [2002] No such file or directory”</a></p><p>2. <a href="https://www.cyberciti.biz/faq/show-all-running-processes-in-linux/">Show All Running Processes in Linux</a></p><h4>The ps command</h4><pre>$ ps -aux | less<br>OR<br>$ ps aux | less</pre><p>3. <a href="https://www.cyberciti.biz/faq/check-running-services-in-rhel-redhat-fedora-centoslinux/">Check Running Services in linux</a></p><pre>service --status-all<br>service --status-all | grep [service_name]</pre><p>4. <a href="https://stackoverflow.com/questions/43559233/rails-whenever-and-docker-cron-tasks-doesnt-run">Rails, Whenever in Docker: cron tasks doesn’t run</a></p><blockquote><strong>RUN</strong> command is only execute when building the <strong>image</strong>.</blockquote><blockquote>If you want to start <strong>cron</strong> when you start your container, you should run <strong>cron</strong> in <strong>CMD</strong> .</blockquote><pre># update cron tasks using whenever<br>RUN bundle exec whenever --update-crontab</pre><pre># execute a command using <strong>CMD</strong> not RUN<br>CMD cron</pre><p>5. <a href="https://forums.docker.com/t/install-cron-in-docker-container-based-on-ruby/32930">Dockerfile to install cron occur error <strong>Unable to locate package cron</strong></a></p><blockquote>Must use<strong> </strong>apt-get update<strong> </strong>before<strong> </strong>apt-get install<strong> </strong>packages.</blockquote><p>6. Mongodb Unauthorized: not authorized on user to executecommand</p><p>Means this user doesn’t have authority to access db.</p><ol><li><em>enter mongodb using </em><em>mongodb --noauth</em></li><li>use admin to enter admin db</li><li>create user for admin</li><li>exit mongodb then connect mongodb by the admin user you just created</li><li>use db you want to create</li><li>create user for db e.g. user, password, readWrite role</li><li>edit mongoid.yml</li></ol><p><a href="http://qqbuby.github.io/docker/2017/09/08/how-to-deploy-mongodb-with-docker.html">How to Deploy MongoDB with Docker</a></p><p>7. <a href="https://github.com/docker-library/mongo/issues/62">Detected unclean shutdown — /data/db/mongod.lock is not empty.</a></p><p><a href="https://stackoverflow.com/questions/9953295/how-to-repair-my-mongodb">https://stackoverflow.com/questions/9953295/how-to-repair-my-mongodb</a></p><p><strong><em>Detected unclean shutdown - mongod.lock is not empty.</em></strong></p><pre>mongod --repair</pre><p>an then start your db.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=356312d54f89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker]]></title>
            <link>https://medium.com/@stan5566/docker-a3e4bb411f0?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3e4bb411f0</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Fri, 15 Dec 2017 02:48:00 GMT</pubDate>
            <atom:updated>2018-01-17T09:49:25.402Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. install docker</h3><p>if you’re using mac and you also love to use brew. Install docker like this</p><pre>brew cask install docker</pre><h3>2. Use docker</h3><p>Docker is similar in git.</p><p>It has repository, e.g. Ubuntu, Ruby, Python and so on. It has tags for versions in every repository. e.g. Ubuntu:16.04 (if you leave it blank, it will install the latest). It has images as we mention asUbuntu:16.04 or Ubuntu:latest.</p><p>And the actions is similar in git.</p><pre>docker pull # pull a image<br>docker commit # commit changes<br>docker push # push a image</pre><blockquote>Don’t use docker commit to edit image, Using Dockerfile</blockquote><blockquote>Docker image is base on every sub layers. If you change configurations of image, it builds a new sub layer base on your old layers so it means if you edit your image and commit it. It will keep the old sub layers and create a edited new layer on its. Make the image too fat either unnecessary. Besides you, other teammates couldn’t know what did you edit the configurations of this image. You would forget someday.</blockquote><h3>3. Dockerfile</h3><h4>Always using Dockerfile to create your image.</h4><pre># choose a image, &#39;From&#39; must always in the file and on the top.<br>FROM ubuntu </pre><pre># exec a command, (same command should use only one line)<br>RUN apt-get update -q \<br>      &amp;&amp; apt-get install \<br>      &amp;&amp; nodejs \</pre><blockquote>Same command should use only one RUN</blockquote><blockquote>Because every RUN command builds a sub layer. If you doing like this</blockquote><blockquote>RUN apt-get update -q<br>RUN apt-get install<br>RUN nodejs<br>...</blockquote><blockquote>it builds 3 or more sub layers on those similar commands. these sub layers make your image fat and builds too many unnecessary sub layers, need more integration time and easy to make some mistakes.</blockquote><h4><strong>ENV for environment configuration</strong></h4><p>There are two kinds of format.</p><ul><li>ENV (Key) (Value)</li><li>ENV (Key1)=(Value1) (Key2)=(Value2)...</li></ul><p>This is official node image dockerfile</p><pre>ENV NODE_VERSION 7.2.0<br><br>RUN curl -SLO &quot;https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz&quot; \<br>  &amp;&amp; curl -SLO &quot;https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc&quot; \<br>  &amp;&amp; gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \<br>  &amp;&amp; grep &quot; node-v$NODE_VERSION-linux-x64.tar.xz\$&quot; SHASUMS256.txt | sha256sum -c - \<br>  &amp;&amp; tar -xJf &quot;node-v$NODE_VERSION-linux-x64.tar.xz&quot; -C /usr/local --strip-components=1 \<br>  &amp;&amp; rm &quot;node-v$NODE_VERSION-linux-x64.tar.xz&quot; SHASUMS256.txt.asc SHASUMS256.txt \<br>  &amp;&amp; ln -s /usr/local/bin/node /usr/local/bin/nodejs</pre><p>You could use env variable $NODE_VERSION within RUN command line</p><h4>Volume for storage</h4><p>There are two kinds of format.</p><ul><li>VOLUME [&quot;path1&quot;, &quot;path2&quot;]</li><li>VOLUME (path)</li></ul><p>Database should save in volume. Because volume is the only one could keep datas, edits in container.</p><pre>VOLUME /data</pre><p>/data will load when run.</p><p>Of course you can override the volume.</p><pre>$ docker run -d -v mydata:/data xxxx</pre><p><a href="https://docs.docker.com/engine/reference/builder/#parser-directives">More about Dockerfile format</a></p><h3>4. Docker Compose</h3><p><em>Defining and running multi-container Docker applications</em></p><h4>Docker-Compose yaml format</h4><p>Through docker-compose.ymlto create a project contains multiple containers.</p><ul><li>Service : a application container could include many images</li><li>project : a full-business module composed by sets of association application containers</li></ul><pre>version: &#39;3&#39; # docker-compose version, now the latest is &#39;3&#39;<br>services:<br>  # declare 2 service with name, build, ports<br>  web:<br>    build: . # build the dockerfile in . path<br>    ports:<br>      - 5001:5000 # map local port 5001 to container 5000<br>  redis:<br>    image: &quot;redis:alpine&quot;</pre><ul><li>build</li><li>command</li><li>container_name</li><li>image</li><li>ports</li></ul><p># (HOST: CONTAINER) or (HOST:CONTAINER:ro)</p><p>volumes:</p><ul><li>secrets</li><li>volumes</li></ul><pre># (HOST: CONTAINER) or (HOST:CONTAINER:ro)</pre><pre>volumes:<br>  - /var/lib/mysql<br>  - cache/:/tmp/cache<br>  - ~/configs:/etc/configs/:ro</pre><ul><li>deploy</li><li>depends_on</li></ul><p><em>will run depends_on first then the service who was depended</em></p><ul><li>env_file</li></ul><pre>env_file: .env</pre><pre>env_file:<br>  - ./common.env<br>  - ./app/web.env<br>  - ./opt/secrets.env</pre><p>env file should conform env format. using # for comment</p><pre># common.env: Set development environment <br>PROG_ENV=development</pre><ul><li>environment</li><li>expose</li></ul><p>Only expose port for linked service in container.</p><pre>nginx:<br>  ports:<br>    - &quot;8080:80&quot;<br>  links:<br>    - web</pre><pre>web:<br>  expose:<br>    - &quot;90&quot;<br>  <br># nginx could proxy_pass <a href="http://web:90/">http://web:90</a> </pre><p>read env varaible</p><pre>db:<br>  image: &quot;mongo:$(MONGO_VERSION)&quot;</pre><p>run docker-compose</p><pre>$ docker-compose up</pre><h4>docker-compose command instructions</h4><p>Here only list commands useful for me</p><ul><li>build</li></ul><pre>docker-compose build [option] [service] ...</pre><p><em>build a container like docker build</em></p><ul><li>config</li></ul><p><em>to valid compose.yml format is correct, it correct shows configurations otherwise shows error description</em></p><ul><li>exec</li></ul><p><em>get into containers so we could exec some command</em></p><ul><li>ps</li></ul><p><em>like docker ps to list current containers</em></p><ul><li>run</li></ul><p><em>run a command</em></p><ul><li>up</li></ul><p><em>activate a container</em></p><ul><li>down</li></ul><p><em>stop container which using</em><em>up activates and shut down network</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3e4bb411f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vapor (1) Install Vapor]]></title>
            <link>https://medium.com/@stan5566/vapor%E4%B9%8B%E8%B7%AF-1-install-vapor-1d3983f83ae2?source=rss-480c3aeb0070------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d3983f83ae2</guid>
            <category><![CDATA[vapor]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Stan Liu]]></dc:creator>
            <pubDate>Wed, 22 Nov 2017 09:32:43 GMT</pubDate>
            <atom:updated>2017-11-22T09:34:40.886Z</atom:updated>
            <content:encoded><![CDATA[<h3>Install Vapor</h3><ol><li>首先你要先檢查你電腦裡的swift 版本</li></ol><pre>curl -sL check.vapor.sh | bash</pre><p>如果他跟你說你電腦裡的swift 版本太低，那就必須要安裝新版。</p><p>如果是macOS，可以到App Store下載Xcode，下載完了或是你原本就已經安裝最新的Xcode，但他還是跟你說你的swift版本太舊。首先可以用指令檢查(這邊要先安裝swiftenv，我是用 brew 來安裝）</p><pre>swiftenv install 4.0.2</pre><p>這時候他可能會說 4.0.2 is already installed. 這是因為你已經安裝好Xcode，所以電腦裡面已經有Swift 4.0.2。</p><p>我們就來設定Swift version</p><pre>swiftenv local 4.0.2</pre><p>因為我不想要設定到global的swift version導致其他問題發生，所以我在我想要vapor在的那個資料夾，(這時候還沒安裝vapor)，但是我先mkdir一個資料夾，設定這一個專案在這個資料夾裡的swift version。(你也可以在資料夾裡新增一個 .swiftversion的文件，裡面寫上 swfit-version: 4.0.2)</p><p>當然你也可以設定global version</p><pre>swiftenv global 4.0.2</pre><p>2. 安裝Vapor</p><p>因為我個人喜歡用brew與cask來管理電腦的套件，so</p><pre># 因為brew 沒有vapor，所以這邊我們用 brew tap 自己創一個<br>brew tap vapor/homebrew-tap</pre><pre># 創完要update<br>brew update</pre><pre># 從剛剛的tap安裝vapor<br>brew install vapor</pre><blockquote><strong>ref: </strong><a href="https://stackoverflow.com/questions/34408147/what-does-brew-tap-mean"><strong>What does brew tap mean</strong></a></blockquote><p>安裝好以後先檢查vapor能不能使用</p><pre>vapor --help<br>&gt;&gt; Usage: vapor command<br>...</pre><p>首先新增一個專案，使用方式類似其他web framework</p><pre>vapor new CURRENCY_API</pre><pre>cd CURRENCY_API</pre><p>使用Xcode打開剛剛產生的專案</p><pre>vapor xcode</pre><pre>&gt;&gt; Generating Xcode Project [Done]<br>&gt;&gt; Select the `Run` scheme to run.<br>&gt;&gt; Open Xcode project?<br>&gt;&gt; y/n&gt; y</pre><p>輸入y就打開Xcode囉！</p><p>選好target “run” 模擬器選Mac 就可以跑了，會在Console看到下面</p><pre>The current hash key &quot;0000000000000000&quot; is not secure.<br>Update hash.key in Config/crypto.json before using in production.<br>Use `openssl rand -base64 &lt;length&gt;` to generate a random string.<br>The current cipher key &quot;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=&quot; is not secure.<br>Update cipher.key in Config/crypto.json before using in production.<br>Use `openssl rand -base64 32` to generate a random string.<br>Database prepared<br>No command supplied, defaulting to serve...</pre><p>現在來試試看簡單寫一個 http 的請求</p><pre>try drop.setup()</pre><pre>drop.get(&quot;/&quot;) { (request) -&gt; ResponseRepresentable in<br>  return &quot;Hello World!&quot;<br>}</pre><pre>try drop.run()</pre><p>這時候我們用瀏覽器打開 0.0.0.0:8080 做對的話就可以看到上面傳的 Hello World! Vapor預設在 8080 port 執行，如果想更改，可以到configuration中修改 servers.json</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d3983f83ae2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>