Docker闀滃儚涓庡埗浣滅殑涓夌鏂瑰紡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker闀滃儚涓庡埗浣滅殑涓夌鏂瑰紡相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%bf%ae%e6%94%b9' title='淇敼'>淇敼
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闀滃儚涓庡埗浣滅殑涓夌鏂瑰紡的主要内容,如果未能解决你的问题,请参考以下文章
wsl2涓婄敤docker閮ㄧ讲杩愯鐜锛宮vn鏋勫缓闀滃儚鎵句笉鍒癲ockerhost
.netMVC:Web椤甸潰鍚戝悗鍙版彁浜ゆ暟鎹殑鏂瑰紡鍜岄€夋嫨
IIS7.0 Windows Server 2008 R2 涓嬮厤缃瘉涔︽湇鍔″櫒鍜孒TTPS鏂瑰紡璁块棶缃戠珯