docker使用alpine鏡像


alpine介紹

alpine簡要介紹

 Alpine 的意思是“高山的”,比如 Alpine plants高山植物,Alpine skiing高山滑雪、the alpine resort阿爾卑斯山勝地。

alpine系統特點 

  1. 小巧:基於Musl libcbusybox,和busybox一樣小巧,最小的Docker鏡像只有5MB;

  2. 安全:面向安全的輕量發行版;

  3. 簡單:提供APK包管理工具,軟件的搜索、安裝、刪除、升級都非常方便。

  4. 適合容器使用:由於小巧、功能完備,非常適合作為容器的基礎鏡像。

alpine鏡像的使用

官方 Alpine 鏡像的文檔:http://gliderlabs.viewdocs.io/docker-alpine/

docker pull alpine
docker run -it --name myalpine alpine:v1

下載鏡像

  1. 在線在docker官方倉庫下載 倉庫在國外,不好拉取鏡像

#查看官方alpine鏡像
docker search  alpine

#拉取鏡像
docker  image pull  itsthenetework/nfs-server-alpine

# 導入nginx鏡像(推薦使用)
docker load  -i  docker_nginx.tar.gz

  2. 離線下載 alpine-3.10下載地址 alpine-3.11下載地址

# 導入nginx鏡像(推薦使用)
docker load  -i  docker_nginx.tar.gz

更新鏡像源

  因為官方源在國外,我們改成國內的清華源

docker run -it -p 80:80 alpine:latest 
/ # sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories 
/ # apk update

  安裝nginx

/ # apk add nginx 
/ # mkdir /run/nginx
/ # nginx 

  注: 打開網頁出現404原因 答:沒有原因,默認配置文件默認寫的就是顯示404

return 404;
#替換
root /html;
index index.html;

  提交成鏡像

docker commit  <alpineID>  nginx_alpine:v1 
docker run -d -p 81:80 nginx_alpine:v1 nginx -g 'daemon off;'

alpine安裝kod

  1. 啟動alpine容器

docker run -it -p 80:80 alpine:v1  
/ # sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories 
/ # apk update
/ # apk add nginx 
/ # mkdir /run/nginx
/ # nginx 
/ # apk add php7 php7-fpm php7-opcache php7-curl php7-gd php7-mbstring php7-mysqli php7-json php7-iconv php7-exif php7-ldap php7-pdo php7-session php7-xml

安裝 rc-service

apk add openrc --no-cache

啟動nginx

service nginx start
#或者rc-service nginx start

遇到問題

WARNING: nginx is already starting

/#  service nginx status
* You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel
/#  touch /run/openrc/softlevel
touch: /run/openrc/softlevel: No such file or directory
/#  mkdir -p /run/openrc
/#  touch /run/openrc/softlevel
/#  service nginx status
 * status: stopped
/#  service nginx start
 * WARNING: nginx is already starting
/#  /sbin/openrc
 * Caching service dependencies ...                                                 [ ok ]
/#  rc-service nginx start
 * /run/nginx: creating directory
 * /run/nginx: correcting owner
 * Starting nginx ...                                                               [ ok ]

啟動php-fpm

vi  /etc/php7/php-fpm.d/www.conf  
所屬主和所著組為nginx
/#  service php-fpm7 start
 * Checking /etc/php7/php-fpm.conf ...
 * /run/php-fpm7: creating directory
 * Starting PHP FastCGI Process Manager ...                                        [ ok ]

加入啟動服務

/#  rc-update add nginx default
/#  rc-update add php-fpm7 default

安裝可道雲

vim  /etc/nginx/conf.d/default.conf  
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    location / {
        root /html;
        index index.php  index.html;
    include /etc/nginx/conf.d./*.conf;
    location ~ \.php$ {
        root        /html;
          fastcgi_pass    127.0.0.1:9000;
    fastcgi_index    index.php;
    fastcgi_param    SCRIPT_FILENAME    /html$fastcgi_script_name;
    include        fastcgi_params;
    }
    }
    # You may need this to prevent return 404 recursion.
    location = /404.html {
        internal;
    }
}

#檢查格式 nginx -t

創建站點目錄

mkdir /html
cd /html
wget http://static.kodcloud.com/update/download/kodexplorer4.40.zip
chown -R nginx:nginx .
#重啟nginx
service nginx restart 
service php-fpm7 restart

啟動腳本文件

vim /init.sh
service nginx start
service nginx restart
service php-fpm7 start
service php-fpm7 restart 
tail -f /etc/hosts

注: 使用腳本時,nginxphp-fpm7啟動一次失敗,所以在這里在重啟一次

 

提交鏡像

 docker commit  optimistic_hermann  alpine_kod:v1 

驗證鏡像

docker run -d -p 80:80 alpine_kod:v1 /bin/sh /init.sh

登錄網站10.0.0.12:80查看

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM