国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

docker 手動構建新鏡像的方法

2024-09-01 13:56:09
字體:
來源:轉載
供稿:網友

本文介紹了docker 手動構建新鏡像的方法,分享給大家,具體如下:

查看本地現有鏡像:

[root@docker ~]# docker imagesREPOSITORY     TAG         IMAGE ID      CREATED       SIZEnginx        latest       c59f17fe53b0    4 days ago     108MBubuntu       latest       747cb2d60bbe    3 weeks ago     122MBcentos       latest       196e0ce0c9fb    6 weeks ago     197MB

現在利用基礎鏡像centos,在此基礎上手動構建一個web服務,這里采用nginx

啟動一個container并進入到容器內:

[root@docker ~]# docker run -it --name=web centos /bin/bash[root@bab3b6991467 /]#

然后在容器內進行安裝nginx服務:

[root@bab3b6991467 /]# cd /usr/local/src/[root@bab3b6991467 src]# yum install wget vim

這里采用編譯安裝nginx,所以下載nginx源碼包,并安裝好編譯環境:

[root@bab3b6991467 src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz

編譯環境:

[root@bab3b6991467 src]# yum install gcc gcc-c++ glibc make autoconf openssl openssl-devel

安裝nginx的一些依賴包:

[root@bab3b6991467 src]# yum install libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel

然后開支執行安裝:

[root@bab3b6991467 src]# lltotal 960-rw-r--r--. 1 root root 981687 Oct 17 13:20 nginx-1.12.2.tar.gz[root@bab3b6991467 src]# tar xf nginx-1.12.2.tar.gz [root@bab3b6991467 src]# cd nginx-1.12.2[root@bab3b6991467 nginx-1.12.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module  --with-http_addition_module  --with-http_xslt_module  --with-http_image_filter_module  --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module  --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module  --with-http_secure_link_module  --with-http_degradation_module  --with-http_stub_status_module

創建需要用到的用戶:

useradd -M -s /sbin/nologin nginx

繼續編譯:

make && make installchown -R nginx:nginx /usr/local/nginx/

這里需要介紹nginx命令的一個參數:

[root@bab3b6991467 ~]# /usr/local/nginx/sbin/nginx -h   -g directives : set global directives out of configuration file

-g:為nginx的配置文件設置指令

現在退出container,回到host本機

[root@bab3b6991467 ~]# exitexit

查看此時容器的狀態:

[root@docker ~]# docker ps -aCONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMESbab3b6991467    centos       "/bin/bash"     37 minutes ago   Exited (0) 21 seconds ago            web

利用docker diff查看該容器進行了哪些修改,由于輸出太多,這里不給予顯示了

利用docker commit將web容器進行加層成一個新鏡像:

[root@docker ~]# docker commit --help  Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]  Create a new image from a container's changes  -m, --message string  Commit message  -a, --author string  Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")

現在開始commit:

[root@docker ~]# docker commit -m "compile nginx on centos" web wadeson/centos_nginx:v1sha256:210a202d37b8d2c31155c29adf0c7c0b49cfab7ff38234109919de7f4e76d1de

查看本地鏡像:

[root@docker ~]# docker imagesREPOSITORY       TAG         IMAGE ID      CREATED       SIZEwadeson/centos_nginx  v1         210a202d37b8    33 seconds ago   464MBnginx         latest       c59f17fe53b0    4 days ago     108MBubuntu         latest       747cb2d60bbe    3 weeks ago     122MBcentos         latest       196e0ce0c9fb    6 weeks ago     197MB

docker,鏡像

可以看見剛剛docker commit的新鏡像了,現在由此鏡像進行啟動一個container提供nginx服務:

[root@docker ~]# docker run -d -p80:80 wadeson/centos_nginx:v1 /usr/local/nginx/sbin/nginx -g "daemon off;"c12669357e2b09a05a396ac480a04dd1956303b784f894b615d4edb889a737ab

然后查看container:

[root@docker ~]# docker ps -lCONTAINER ID    IMAGE           COMMAND         CREATED       STATUS       PORTS        NAMESc12669357e2b    wadeson/centos_nginx:v1  "/usr/local/nginx/..."  41 seconds ago   Up 40 seconds    0.0.0.0:80->80/tcp  thirsty_murdock

可以看見nginx服務已經開啟了,于是進行訪問:

docker,鏡像

 于是整個手動構建就成功了

針對上面的一些命令做下解釋:

docker run -d -p80:80 wadeson/centos_nginx:v1 /usr/local/nginx/sbin/nginx -g "daemon off;"

后面運行的命令都是旨在container的命令,由于沒有進行環境變量設置,所以全路徑,而nginx -g這個參數是指可以在外面添加指令到nginx的配置文件中,daemon off是指nginx服務不運行在后端而是在前臺運行(container中的服務必須運行在前臺)

利用docker top可以查看container的運行進程:

[root@docker ~]# docker top c12669357e2bUID         PID         PPID        C          STIME        TTY         TIME        CMDroot        35468        35451        0          02:55        ?          00:00:00      nginx: master process /usr/local/nginx/sbin/nginx -g daemon off;1000        35489        35468        0          02:55        ?          00:00:00      nginx: worker process

利用docker exec進入到容器內:

[root@docker ~]# docker exec -it c12669357e2b /bin/bash[root@c12669357e2b /]# ps -efUID     PID  PPID C STIME TTY     TIME CMDroot     1   0 0 06:55 ?    00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -g daemon off;nginx     5   1 0 06:55 ?    00:00:00 nginx: worker processroot     6   0 1 07:01 pts/0  00:00:00 /bin/bashroot     20   6 0 07:01 pts/0  00:00:00 ps -ef

而使用ctrl+p+q可以將該容器置于后臺,而不是馬上exited

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到服務器教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金乡县| 天等县| 克拉玛依市| 阳山县| 开化县| 突泉县| 德令哈市| 英山县| 达尔| 广南县| 乾安县| 耒阳市| 磐安县| 石泉县| 涪陵区| 九龙坡区| 太原市| 黎城县| 乐至县| 沧源| 新乡县| 二手房| 正镶白旗| 罗定市| 新泰市| 云霄县| 三明市| 武清区| 塔河县| 盐山县| 尉犁县| 荥经县| 龙门县| 棋牌| 八宿县| 江都市| 耒阳市| 长乐市| 南宁市| 星子县| 女性|