【URLOS應用開發基礎】10分鐘製做nginx靜態網站環境應用

URLOS開發者功能已上線有一段時間了,目前經過部分開發者的使用體驗來看,不得不說URLOS在服務器軟件開發效率方面確實有着得天獨厚的優點,憑藉docker容器技術與其良好的應用生態環境,URLOS必將迅速成爲軟件開發者的新寵兒。html

本篇內容以入門爲主,經過製做一個簡單的靜態網站環境應用,讓新晉開發者能在短期內對URLOS的開發流程有所認識。nginx

URLOS基於docker容器技術,所以在應用開發過程當中咱們離不開docker的相關命令,對docker還不太瞭解的朋友,能夠先大體瞭解一下docker的相關內容,本篇不作詳細討論。web

URLOS應用開發的基本流程
在這裏插入圖片描述
本篇目標是製做nginx靜態網站環境,那麼咱們須要作的內容包括:運行一個基礎鏡像,在此鏡像基礎上安裝nginx,設置網站根目錄,打包並上傳新鏡像,經過URLOS添加新應用,發佈並導出應用。docker

製做nginx靜態網站環境

1、拉取Alpine基礎鏡像

爲何選擇Alpine做爲基礎鏡像?由於Alpine的文件體積小啊,基礎鏡像只有5.53MB,相比ubuntu鏡像的88.9MB要小十幾倍。
使用docker pull alpine命令拉取alpine鏡像:json

root@ubuntu:~# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
bdf0201b3a05: Pull complete
Digest: sha256:28ef97b8686a0b5399129e9b763d5b7e5ff03576aa5580d6f4182a49c5fe1913
Status: Downloaded newer image for alpine:latest
root@ubuntu:~#

而後使用docker images命令查看鏡像:ubuntu

root@ubuntu:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
urlos/urlos         latest              4810506f7202        12 hours ago        447MB
alpine              latest              cdf98d1859c1        2 weeks ago         5.53MB
root@ubuntu:~#

2、更新鏡像,安裝nginx

運行Alpine鏡像並進入容器內部:瀏覽器

root@ubuntu:~# docker run -it alpine sh
/ #

更換更新源:服務器

/ # vi /etc/apk/repositories

將其中內容換成阿里雲的源app

/ # cat /etc/apk/repositories
https://mirrors.aliyun.com/alpine/v3.6/main/
https://mirrors.aliyun.com/alpine/v3.6/community/
/ #

使用apk update執行更新:tcp

/ # apk update
fetch https://mirrors.aliyun.com/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
v3.6.5-25-g77eea063d8 [https://mirrors.aliyun.com/alpine/v3.6/main/]
v3.6.5-18-gfdfe1f6192 [https://mirrors.aliyun.com/alpine/v3.6/community/]
OK: 8453 distinct packages available
/ #

使用apk add nginx安裝nginx:

/ # apk add nginx
(1/4) Installing libressl2.5-libcrypto (2.5.5-r2)
(2/4) Installing pcre (8.41-r0)
(3/4) Installing libressl2.5-libssl (2.5.5-r2)
(4/4) Installing nginx (1.12.2-r2)
Executing nginx-1.12.2-r2.pre-install
Executing busybox-1.29.3-r10.trigger
OK: 9 MiB in 18 packages
/ #

保護pid:

/ # cd /run/
/run # mkdir nginx

添加網站根目錄:

/ # mkdir -p /data/www/

修改nginx配置文件:

/data/www # vi /etc/nginx/conf.d/default.conf
/data/www # cat /etc/nginx/conf.d/default.conf
# This is a default site configuration which will simply return 404, preventing
# chance access to any other virtualhost.

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        location / {
                index index.html;
                root /data/www;
        }

        # You may need this to prevent return 404 recursion.
        location = /404.html {
                internal;
        }
}
/data/www #

測試nginx:

/data/www # nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

OK,nginx配置完成!
使用exit退出容器,準備打包鏡像。

/data/www # exit
root@ubuntu:~#

3、打包鏡像

使用命令docker ps -a查看全部容器:

root@ubuntu:~# docker ps -a
CONTAINER ID        IMAGE                COMMAND               CREATED             STATUS                     PORTS                                                                    NAMES
a5249fa1d7ec        alpine               "sh"                  35 minutes ago      Exited (0) 2 minutes ago                                                                            youthful_heisenberg
1502c4163c2c        urlos/urlos:latest   "sh /entrypoint.sh"   2 hours ago         Up 2 hours                 0.0.0.0:9001->9001/tcp, 0.0.0.0:9966->9966/tcp, 0.0.0.0:9968->9968/tcp   urlos
root@ubuntu:~#

使用docker commit命令打包鏡像,而後使用docker images命令查看鏡像:

root@ubuntu:~# docker commit a5249fa1d7ec yeqing112/alpine-nginx:0.0.1
sha256:4730bd89ee3e9408f0ba29c5c80ad0a13600b82de565bbc49f3d4ec8585902c4
root@ubuntu:~# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
yeqing112/alpine-nginx   0.0.1               4730bd89ee3e        13 seconds ago      10MB
urlos/urlos              latest              4810506f7202        13 hours ago        447MB
alpine                   latest              cdf98d1859c1        2 weeks ago         5.53MB
root@ubuntu:~#

OK,咱們成功製做了一個名稱爲yeqing112/alpine-nginx的新鏡像。

4、上傳鏡像

首先使用命令docker login進行登陸,若是沒有docker帳號,請到docker官網註冊:

root@ubuntu:~# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
root@ubuntu:~#

使用docker push命令上傳鏡像:

root@ubuntu:~# docker push yeqing112/alpine-nginx:0.0.1
The push refers to repository [docker.io/yeqing112/alpine-nginx]
bbe56e36ea7a: Pushed
a464c54f93a9: Mounted from library/alpine
0.0.1: digest: sha256:94c5f0c38a3de543cde52791b3daff3fdc8001e99bf58bb08230b2cab3e062a3 size: 739
root@ubuntu:~#

打開docker鏡像倉庫能夠看到咱們上傳的鏡像了
在這裏插入圖片描述
鏡像上傳成功後,訪問http://主機ip:9968登陸URLOS主控,咱們將在這裏面進行應用的添加(沒有安裝URLOS的,百度搜索URLOS,到官網查看安裝方法)。

5、製做URLOS應用

登陸urlos主控後,咱們先檢查URLOS版本和模式是否正確,製做應用咱們須要使用URLOS付費版本,這裏我使用了URLOS標準版,而且須要將模式改成DEV(開發模式),具體修改方法到URLOS官網查看。
在這裏插入圖片描述

添加鏡像

在這裏插入圖片描述
在這裏插入圖片描述

添加應用

我在這一步要偷偷懶,直接複製一個已有應用,而後稍做修改。那咱們選擇複製什麼應用呢?其實官方有一個靜態網站的應用,直接複製過來修改便可。在應用管理列表中搜索nginx關鍵詞,找到系統自帶的靜態網站應用:
在這裏插入圖片描述
點擊更多按鈕,在彈出菜單中選擇複製應用
在這裏插入圖片描述
如下截圖中標紅的內容是必須修改的,其餘內容的修改視我的狀況而定。
基本信息:
這裏咱們就修改應用名稱和鏡像便可。
在這裏插入圖片描述
在當前項目中,其餘選項咱們不須要去修改,由於那些內容跟咱們的需求是同樣的。
點擊提交按鈕,OK,咱們的應用製做完成了!啊?這麼快?沒錯!就是這麼快。
在這裏插入圖片描述
而後咱們經過這個新應用快速的部署一個網站試試,點擊更多,彈出菜單中選擇建立服務
在這裏插入圖片描述
部署完成瀏覽器打開網站,靜態網站成功運行!

咱們還能夠將這個靜態網站應用導出來,轉給其餘用戶導入使用:
在這裏插入圖片描述
導出的是文本文件,體積很是小:
在這裏插入圖片描述
導入應用時,只需將文本中的內容複製黏貼便可:
在這裏插入圖片描述

如下是這個應用導出的文本內容,僅供你們測試:

{
    "appName": "my-nginx-website",
    "appVersion": "0.1.0",
    "appPrivileged": 0,
    "imageUrl": "yeqing112\/alpine-nginx:0.0.1",
    "exportTime": "2019-04-27 14:01:00",
    "exportData": "5Rv8VFcUKLyJEH5nE6rVfoGNG1WKhUI_38OBEL_--7OxDFjRCeo4yB3RLJYz7YCEbOHD4INhvnWNXZIb6Tpj6FPV0rC4GrGvVjgfHTMYsklOTXqsATJgHfZmyny6y-94dgYpdQ33pb1eG0tbASNEi-NWZURzRhxbQefT3ctMIlHNR2fejocppWjAKR-o6h6dyGVEdCZaYmUaf59Un_i-y8yuaPKPWhWY3IolA1dSoZLMv0iKT4e-UubBhZC-hOz1YQT3KeNYgdjGGJKLd0rTc950X6hkwmo0jh8MuGg_RCNtWoe0DFxKjMz_TXbKaBmPbzutco3Xgr2FHGCeI60KAMfdA7EWMV0pIJbRem2_prbctwHfRc2CIq42Uc9CGf4dtrYL0cTbQVztFJ7ZKc4v_hH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9e-an_gEGfEO8EqphKlxYlPViYb3rBuNxQkBKDy4Z4mRu59Q21NFTxDLPH_Ela7zwymbrvquDx52pSKMPUVuRqPdR5-kmIrlOiAdw9hvPpzXHRH6PpALZCpNWPX3qGPPWzJsJ88iEmrAwcMgokIwhr7mgCXo6SUI0z_E8OUNerpR3tpslp-9yahJQO_Wd1DIAexCI0BwHspVT0G23QepSDxKvA47sUURP-DrGeAjSoj9BtAO57HVJeexbURq7DcAuQl8Ye95Xhc9ZHJl-E8vacdzopA3UM8g2htW6qW_TVhDg3D9GltdmzSBdgBl2epcro2c22yD5sWa8oROkAbXXvOumc7rLTb9p_pFy_o86TUebK4U7O0IT9boM8PJTCxhXOcB8gUohGd74kkkpG6kUucGXmlZXcFCplP4bcIKmhYdXtPwqT_gbhUeLvzaWo90qgmhJ_SkzvbkVboZdSCdNh-68ib9o5Wf8FL3BdycCcKLRnKbLF8kFL6RDdJPupojem19kll_Wwb0r31DhgeF9xMVXd2hvtck_EW_c45sbrk_L097-6QBmW4ZVgLCn4_xM7G3sUD2T8Cu--g6xRMP3x2jc4tRfFErE55buKV2y_o-_J8NSuuGojDdLo6KGJ1bbg7Sy92wDYEKzTeDs5u3cxoLd9CRHZ-_FvSGvYRyaxgMv1jo-MFpStswW5kbIy4IxPOkrMneADLd03AWyC_EBTpWCE1_mjPyfbvb8CAiBxcNlEdMukttap8EY22ZX7VytjdWxFVQRN7rrj9bP-bKo_U712c8KGgkuQjRMnQHuVB03-RAjCPlpVu39GbK28YjNEXRt2rdxj0LgGSviZbfgi10nKU9QCN5YdeCTnzidBWLfv_vSbDbKJoiSKg2Pg4gDDc-E85EJZZujRnxc="
}

歡迎廣大開發者一同交流
URLOS官網:https://www.urlos.com/

相關文章
相關標籤/搜索