Docker闀滃儚涓庡埗浣滅殑涓夌鏂瑰紡

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker闀滃儚涓庡埗浣滅殑涓夌鏂瑰紡相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%bf%ae%e6%94%b9' title='淇敼'>淇敼   缂栬瘧   shel   浜や簰   璁剧疆   word   涓嬭浇婧愮爜   

yum 鏂瑰紡瀹夎
1.涓嬭浇鍒濆鍖栭暅鍍?br/>docker pull ubuntu
docker run -it -p 80:80 ubuntu /bin/bash
apt-get update && apt-get install vim -y
vim /etc/apt/sources.list 淇敼涓洪樋閲岀殑闀滃儚婧?br/>apt-get update
2.瀹夎nginx浠ュ強閰嶅杞欢鍖?br/>apt-get install nginx wget libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev iproute2 net-tools iotop -y
寮€鍚痭ginx
nginx -t
nginx
淇敼閰嶇疆鏂囦欢锛屽叧闂悗鍙拌繍琛岋紝鍦?etc/nginx/nginx.conf涓叏灞€閰嶇疆涓坊鍔燿aemon off;
3.鎻愪氦瀹瑰櫒
鏈粓绔笉閫€鍑猴紝鍦ㄥ彟涓€涓粓绔噷
docker commit -a "shitouweb shitouweb@126.com" -m "ubuntu.nginx" 5321db21c49a ubuntu.nginx
-a 闀滃儚浣滆€呯殑鑱旂郴鏂瑰紡
-m 闀滃儚鎻忚堪淇℃伅
-c 闀滃儚鍚姩鏃惰嚜鍔ㄦ墽琛岀殑鍛戒护
瀹瑰櫒ID
鍒涘缓闀滃儚鐨勫悕绉?br/>4.鍚姩瀹瑰櫒
sudo docker run -it -p 8080:80 ubuntu.nginx nginx

缂栬瘧鏂瑰紡瀹夎
1.鍒濆鍖栧鍣?br/>docker run -it -p 80:80 ubuntu /bin/bash
apt-get update && apt-get install gcc vim net-tools -y
2.瀹夎閰嶅杞欢鍖?br/>apt-get install wget libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev iproute2 net-tools iotop gcc g++ automake build-essential -y
3.鍦ㄥ鍣ㄤ腑涓嬭浇婧愮爜骞剁紪璇戝畨瑁?br/>cd /usr/local/src && wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1 && ./configure --prefix=/apps/nginx && make && make install
4.淇敼閰嶇疆鏂囦欢
vim /app/nginx/conf/nginx.conf涓叏灞€閰嶇疆涓坊鍔燿aemon off;
ln -sv /apps/nginx/sbin/nginx /usr/bin/ #鐢熸垚杞摼鎺?br/>5.鐢熸垚闀滃儚
鏈粓绔笉閫€鍑猴紝鍦ㄥ彟涓€涓粓绔噷
docker commit -a "shitouweb shitouweb@126.com" -m "ubuntu.nginx.make" 5321db21c49a ubuntu.nginx:v1
6.鐢熸垚瀹瑰櫒
sudo docker run -it -p 8081:80 ubuntu.nginx:v1 nginx
濡傛灉鎯充紶閫掑弬鏁?br/>sudo docker run -it -p 8081:80 ubuntu.nginx:v1 nginx 鈥?g daemon off;鈥?/p>

dockerfile鏂囦欢鍒朵綔闀滃儚
瀹夎瀹樻柟瑙勫垯瀹氫箟dockerfile鏂囦欢锛岃嚜鍔ㄥ寲闈炰氦浜掑埗浣滈暅鍍忥紝閲岄潰鐨勬病涓€涓楠ら兘鍙互鏌ヨ
1.鍙橀噺涓殑鎸囦护鍒楄〃鏀寔鐜鍙橀噺dockerfile
ADD#娣诲姞鏂囦欢锛屼細瀵箃ar.gz鐨勫帇缂╁寘鑷姩瑙e帇
COPY#娣诲姞鏂囦欢锛屼笉鑳借嚜鍔ㄨВ鍘?br/>ENV#璁剧疆瀹瑰櫒鍙橀噺锛屽父鐢ㄥ悜瀹瑰櫒鍐呬紶閫掔敤鎴峰瘑鐮佺瓑
EXPOSE#瀵瑰鍣ㄦ毚闇茬鍙?br/>FROM#瀹氫箟鍩虹闀滃儚锛岄鍏堝湪鏈湴鎵撅紝鏈湴娌℃湁鐩存帴涓嬭浇
LABEL#缁存姢淇℃伅LABEL maintainer="shitouweb <shitouweb@126.com>"
STOPSIGNAL
USER#鎸囧畾璇ュ鍣ㄨ繍琛屾椂鐨勭敤鎴峰悕鍜孶ID锛屽悗缁殑RUN鍛戒护涔熶細浣跨敤杩欓潰鎸囧畾鐨勭敤鎴锋墽琛?br/>VOLUME#璁剧疆瀹瑰櫒鎸傝浇涓绘満鐩綍
WORKDIR#鎸囧畾宸ヤ綔鐩綍
RUN#鎵цshell鍛戒护锛屾暣涓繃绋嬮潪浜や簰寮忕殑
CMD#瀹氫箟鍚姩闀滃儚鐨勬椂鍊欓粯璁ゆ墽琛岀殑鍛戒护
2.鍩轰簬dockerfile鍒涘缓docker闀滃儚
鍒涘缓鐩綍锛歮kdir -p /opt/dockerfile/web/nginx
鍒涘缓Dcokerfile鏂囦欢
vim Dockerfile #娉ㄦ剰鏂囦欢鏍煎紡锛岀涓€涓狣蹇呴』鏄ぇ鍐欙紝鏂囦欢鍚嶅繀椤讳竴妯′竴鏍?br/>#Docker image for nginx

FROM ubuntu

LABEL  maintainer="shitouweb <shitouweb@126.com>"

ENV password 123456

RUN apt-get update && apt-get install -y wget libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev iproute2 net-tools iotop gcc g++ automake build-essential unzip

ADD nginx-1.16.1.tar.gz /usr/local/src

RUN cd /usr/local/src/nginx-1.16.1 && ./configure --prefix=/apps/nginx && make && make install && rm -rf nginx-1.16.1 

ADD static.zip /apps/nginx/html

RUN cd /apps/nginx/html && unzip static.zip && rm -rf static.zip 

EXPOSE 80 443

CMD ["/apps/nginx/sbin/nginx" , "-g" , "daemon off;"]

鍒涘缓闀滃儚
docker build -t nginx:v2 . #娉ㄦ剰鏈€鍚庣殑閭d釜灏忕偣
楠岃瘉瀹瑰櫒
docker run --rm -it 80:80 nginx:v2 /bin/bash
--rm鍙傛暟锛氶€€鍑轰箣鍚庤嚜鍔ㄥ垹闄ゃ€?/p>

以上是关于Docker闀滃儚涓庡埗浣滅殑涓夌鏂瑰紡的主要内容,如果未能解决你的问题,请参考以下文章

cpu涓庡璁捐繘琛屾暟鎹氦鎹㈢殑鏂瑰紡

wsl2涓婄敤docker閮ㄧ讲杩愯鐜锛宮vn鏋勫缓闀滃儚鎵句笉鍒癲ockerhost

.netMVC:Web椤甸潰鍚戝悗鍙版彁浜ゆ暟鎹殑鏂瑰紡鍜岄€夋嫨

IIS7.0 Windows Server 2008 R2 涓嬮厤缃瘉涔︽湇鍔″櫒鍜孒TTPS鏂瑰紡璁块棶缃戠珯

浣跨敤buildpack-deps 鏋勫缓鑷繁鐨勫叆瀹瑰櫒闀滃儚

鏇存敼pip婧愯嚦鍥藉唴闀滃儚锛屾樉钁楁彁鍗囦笅杞介€熷害