前言

因为之前根据一些网上的教程一个个部分实践过整个部署流程,但都是根据现有的程序/ymal文件等进行创建部署,未能根据自己特定的项目进行部署。因此,这篇博文,打算完整部署一个自己编写的python+flask+html项目。

构建镜像的过程中有很多出现的问题,笔者把过程也都列出来了,或许有些朋友会遇到一些类似的问题,可供参考。若是觉得累赘,也可直接跳到关键步骤进行查看(都标出来了)

此帖主要为记录自己部署的流程!

第一步:构建镜像

0 第一次构建

# 创建项目文件夹
root@master:/home/hqc/docker_learning# mkdir plus-of-arrays# 创建模板文件夹用于存放html文件
root@master:/home/hqc/docker_learning/plus-of-arrays# mkdir templates# 编写html文件
root@master:/home/hqc/docker_learning/plus-of-arrays# vim plus.html<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>plus of array</title></head><body>list1 is :{{list1}}<br>list2 is :{{list2}}<br><br>list1 plus list2 is : {{list}}</body></html>
# 实现的是两个数组相加的功能root@master:/home/hqc/docker_learning/plus-of-arrays# ls
plus.html  templates
root@master:/home/hqc/docker_learning/plus-of-arrays# mv plus.html templates/
root@master:/home/hqc/docker_learning/plus-of-arrays# ls
templates
# 将创建的html文件移入模板文件夹中# 编写python程序
root@master:/home/hqc/docker_learning/plus-of-arrays# vim array-plus.py#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/12/10 上午10:14# @Author : hqc# @File : plus_of_array.py# @Software: PyCharmfrom flask import Flask,render_templateapp = Flask(__name__)@app.route('/index')def index():list1 = [1,2,3,4,5,6]list2 = [2,3,4,5,6,7]list = [ list1[i]+list2[i] for i in range(min(len(list1),len(list2))) ]return render_template('plus.html',list = list,list1 = list1,list2 = list2)if __name__ == '__main__':app.run()root@master:/home/hqc/docker_learning/plus-of-arrays# ls
array-plus.py  templates# 验证程序效果
root@master:/home/hqc/docker_learning/plus-of-arrays# python array-plus.py * Serving Flask app 'array-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)127.0.0.1 - - [10/Dec/2021 11:36:18] "GET /index HTTP/1.1" 200 -127.0.0.1 - - [10/Dec/2021 11:36:19] "GET /index HTTP/1.1" 200 -# 编写Dockerfile文件
root@master:/home/hqc/docker_learning/plus-of-arrays# vim Dockerfile
FROM python
RUN mkdir -p /array-plus \
COPY ./templates/* /array-plus/
COPY array-plus.py /array-plus/
EXPOSE 80
RUN /bin/bash -c 'echo init ok'# 构建镜像
root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v1.0 .Sending build context to Docker daemon  4.608kBStep 1/6 : FROM python---> f48ea80eae5aStep 2/6 : RUN mkdir -p /array-plus---> Using cache---> 2e1bfa6c2c76Step 3/6 : COPY ./templates/* /array-plus/---> 385c39be4fbaStep 4/6 : COPY array-plus.py /array-plus/---> 5523bef7ba17Step 5/6 : EXPOSE 80---> Running in 10de283ba678Removing intermediate container 10de283ba678---> 922b030ff0a1Step 6/6 : RUN /bin/bash -c 'echo init ok'---> Running in 32e175765578init okRemoving intermediate container 32e175765578---> 0ed6350571d5Successfully built 0ed6350571d5Successfully tagged array-plus:v1.0# 运行
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run array-plus:v1.0
# 发现并无任何结果,可能是少了ui文件

1 尝试解决1

分析原因:结合上次部署html项目时需要加入一个ui界面用于显示的经验来说,可能是少了ui文件

# 修改Dokcerfile
root@master:/home/hqc/docker_learning/plus-of-arrays# vim DockerfileFROM pythonRUN mkdir -p /array-plus \&& rm /etc/nginx/conf.d/default.confCOPY ./templates/* /array-plus/COPY array-plus.py /array-plus/COPY plus.conf /etc/nginx/conf.d/default.confEXPOSE 80RUN /bin/bash -c 'echo init ok'# 编写名为plus.conf的ui文件
server {listen 80;location / {root /array-plus/;index lovestory.html; # 源码文件}}# 再次构建
root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v1.1 .Sending build context to Docker daemon  5.632kBStep 1/7 : FROM nginx---> ea335eea17abStep 2/7 : RUN mkdir -p /array-plus     && rm /etc/nginx/conf.d/default.conf---> Running in 73364b010397Removing intermediate container 73364b010397---> efcd0c60672dStep 3/7 : COPY ./templates/* /array-plus/---> 67fbcbf54aedStep 4/7 : COPY array-plus.py /array-plus/---> 2613cca37078Step 5/7 : COPY plus.conf /etc/nginx/conf.d/default.conf---> 9b49e46e5093Step 6/7 : EXPOSE 80---> Running in 83c146f1ac45Removing intermediate container 83c146f1ac45---> b7778c67197cStep 7/7 : RUN /bin/bash -c 'echo init ok'---> Running in 4585a0bb8fd7init okRemoving intermediate container 4585a0bb8fd7---> e3cddd224cc5Successfully built e3cddd224cc5Successfully tagged array-plus:v1.1# 再次运行
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run array-plus:v1.1/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d//docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh/docker-entrypoint.sh: Configuration complete; ready for start up2021/12/10 03:54:16 [notice] 1#1: using the "epoll" event method2021/12/10 03:54:16 [notice] 1#1: nginx/1.21.42021/12/10 03:54:16 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 2021/12/10 03:54:16 [notice] 1#1: OS: Linux 5.4.0-91-generic2021/12/10 03:54:16 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:10485762021/12/10 03:54:16 [notice] 1#1: start worker processes2021/12/10 03:54:16 [notice] 1#1: start worker process 30...
# 运行效果不对,可能需要暴露端口什么的# 再次运行,成功
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1111:80 array-plus:v1.1
55f463aa181dd84edf3fb83232fdc4d4fb0cbad6076b170d54f93aef4e5f00ee

但是,ip+端口号访问失败

2 尝试解决2

分析原因:怀疑可能是py程序后面要跟的‘/index’的问题

# 遂修改py程序
root@master:/home/hqc/docker_learning/plus-of-arrays# vim array-plus.py#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/12/10 上午10:14# @Author : hqc# @File : plus_of_array.py# @Software: PyCharmfrom flask import Flask,render_templateapp = Flask(__name__)@app.route('/') def index():list1 = [1,2,3,4,5,6]list2 = [2,3,4,5,6,7]list = [ list1[i]+list2[i] for i in range(min(len(list1),len(list2))) ]return render_template('plus.html',list = list,list1 = list1,list2 = list2)if __name__ == '__main__':app.run()root@master:/home/hqc/docker_learning/plus-of-arrays# ls
array-plus.py  templates
# 修改为根目录‘/’root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v1.2 .Sending build context to Docker daemon  5.632kBStep 1/7 : FROM nginx---> ea335eea17abStep 2/7 : RUN mkdir -p /array-plus     && rm /etc/nginx/conf.d/default.conf---> Using cache---> efcd0c60672dStep 3/7 : COPY ./templates/* /array-plus/---> Using cache---> 67fbcbf54aedStep 4/7 : COPY array-plus.py /array-plus/---> d1856a23fa81Step 5/7 : COPY plus.conf /etc/nginx/conf.d/default.conf---> d26866bbdc37Step 6/7 : EXPOSE 80---> Running in 906672daa310Removing intermediate container 906672daa310---> 2c51759a4becStep 7/7 : RUN /bin/bash -c 'echo init ok'---> Running in 8b87e01ac112init okRemoving intermediate container 8b87e01ac112---> b48902c70940Successfully built b48902c70940Successfully tagged array-plus:v1.2root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1112:80 array-plus:v1.212b61389ec321693aec05db88a5d7b0df585e17af3cf418e635aeaf97bf584b7

仍然无法访问:

3 尝试解决3

分析原因:可能是py程序默认端口是5000的问题,而不应该是80

# 修改Dockerfile
root@master:/home/hqc/docker_learning/plus-of-arrays# vim DockerfileEXPOSE 5000# 修改plus.conf
root@master:/home/hqc/docker_learning/plus-of-arrays# vim plus.conflisten 5000root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v1.3 .Sending build context to Docker daemon  5.632kBStep 1/7 : FROM nginx---> ea335eea17abStep 2/7 : RUN mkdir -p /array-plus     && rm /etc/nginx/conf.d/default.conf---> Using cache---> efcd0c60672dStep 3/7 : COPY ./templates/* /array-plus/---> Using cache---> 67fbcbf54aedStep 4/7 : COPY array-plus.py /array-plus/---> Using cache---> d1856a23fa81Step 5/7 : COPY plus.conf /etc/nginx/conf.d/default.conf---> e2f7f1d236e7Step 6/7 : EXPOSE 5000---> Running in 2bd9f2d36bdcRemoving intermediate container 2bd9f2d36bdc---> 5cc24d47cdebStep 7/7 : RUN /bin/bash -c 'echo init ok'---> Running in 3e7532707bcdinit okRemoving intermediate container 3e7532707bcd---> 080098572156Successfully built 080098572156Successfully tagged array-plus:v1.3
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1113:5000 array-plus:v1.34786aa5b12f6d7aa114cbf1b4dbf2ea4a399c0fb25b9036eb76bee843213688e

仍然失败!!!qswl

4 尝试解决4

# 查看运行中的容器
root@master:/home/hqc/docker_learning/plus-of-arrays# docker psCONTAINER ID   IMAGE             COMMAND                  CREATED       STATUS       PORTS                                               NAMES4786aa5b12f6   array-plus:v1.3   "/docker-entrypoint.…"   4 hours ago   Up 4 hours   80/tcp, 0.0.0.0:1113->5000/tcp, :::1113->5000/tcp   elastic_swirles12b61389ec32   array-plus:v1.2   "/docker-entrypoint.…"   4 hours ago   Up 4 hours   0.0.0.0:1112->80/tcp, :::1112->80/tcp               relaxed_merkle55f463aa181d   array-plus:v1.1   "/docker-entrypoint.…"   4 hours ago   Up 4 hours   0.0.0.0:1111->80/tcp, :::1111->80/tcp               hungry_wright# 进入该容器进行查看
root@master:/home/hqc/docker_learning/plus-of-arrays# docker exec -it 12b61389ec32 /bin/bash
root@12b61389ec32:/# ls
array-plus  bin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@12b61389ec32:/# cd array-plus/
root@12b61389ec32:/array-plus# ls
array-plus.py  plus.html
# 发现里边的目录结构和本机中的不同,需要调整# 修改Dockerfile
root@master:/home/hqc/docker_learning/plus-of-arrays# vim DockerfileFROM nginxRUN mkdir -p /array-plus \&& mkdir -p /array-plus/templates \&& rm /etc/nginx/conf.d/default.confCOPY ./templates/* /array-plus/templatesCOPY array-plus.py /array-plus/COPY plus.conf /etc/nginx/conf.d/default.confEXPOSE 5000RUN /bin/bash -c 'echo init ok'root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v1.5 .Sending build context to Docker daemon  5.632kBStep 1/7 : FROM nginx---> ea335eea17abStep 2/7 : RUN mkdir -p /array-plus     && mkdir -p /array-plus/templates     && rm /etc/nginx/conf.d/default.conf---> Using cache---> 52cdfa067df3Step 3/7 : COPY ./templates/* /array-plus/templates---> f0b746b473baStep 4/7 : COPY array-plus.py /array-plus/---> 4bf1d3f2b49dStep 5/7 : COPY plus.conf /etc/nginx/conf.d/default.conf---> 257f3c1d8d37Step 6/7 : EXPOSE 5000---> Running in ecebc719a0edRemoving intermediate container ecebc719a0ed---> 1ee4941610efStep 7/7 : RUN /bin/bash -c 'echo init ok'---> Running in baf0c12e99a2init okRemoving intermediate container baf0c12e99a2---> 07d60b8f1224Successfully built 07d60b8f1224Successfully tagged array-plus:v1.5
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1115:5000 array-plus:v1.555e31feeaed7ddc9217b0ef9ed4058e0a6afd175798beb01810b06ef9232bbf1

仍然无法正常访问!

# 进入该容器查看
root@master:/home/hqc/docker_learning/plus-of-arrays# docker exec -it 55e31feeaed7 /bin/bashroot@55e31feeaed7:/# lsarray-plus  bin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run sbin  srv  sys  tmp  usr  var
root@55e31feeaed7:/# cd array-plus/
root@55e31feeaed7:/array-plus# lsarray-plus.py  templates
root@55e31feeaed7:/array-plus# cd templates/
root@55e31feeaed7:/array-plus/templates# lsplus.html
# 可见,文件目录是正确的root@55e31feeaed7:/array-plus/templates# cd ..
# 在容器中直接运行试试
root@55e31feeaed7:/array-plus# python array-plus.py bash: python: command not found
# 报错:未能找到该命令

5 尝试解决5(关键步骤)

分析原因:不能基于nginx制作镜像,因为里边没有配置python和flask环境,自然无法运行该项目;另外,可能并不需要制作ui界面

root@master:/home/hqc/docker_learning/plus-of-arrays# vim DockerfileFROM pythonRUN mkdir -p /array-plus \&& mkdir -p /array-plus/templates \&& pip install flaskCOPY ./templates/plus.html /array-plus/templatesCOPY array-plus.py /array-plus/WORKDIR /array-plus# COPY plus.conf /etc/nginx/conf.d/default.confEXPOSE 5000RUN /bin/bash -c 'echo init ok'CMD ["python", "array-plus.py"]
  1. WORKDIR /array-plus语句的作用是:进入该容器时会默认进入工作目录
  2. 添加了CMD ["python", "array-plus.py"]语句,用来执行py程序
  3. 最重要的是换了基础镜像python,以及添加了pip install flask语句用来配置flask环境
  4. 注意拷贝本机文件到容器中的方式:COPY ./templates/plus.html /array-plus/templates
# 运行该镜像
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1116:5000 array-plus:v1.6

访问失败????

但失败界面和之前403报错的不同了,也不知道是为啥。。

# 进入容器查看
root@master:/home/hqc/docker_learning/plus-of-arrays# docker exec -it 9c1312d06381 /bin/bash# 在容器中运行程序
root@9c1312d06381:/array-plus# python array-plus.py * Serving Flask app 'array-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: offTraceback (most recent call last):File "/array-plus/array-plus.py", line 19, in <module>app.run()File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 920, in runrun_simple(t.cast(str, host), port, self, **options)File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 1010, in run_simpleinner()File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 950, in innersrv = make_server(File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 782, in make_serverreturn ThreadedWSGIServer(File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 688, in __init__super().__init__(server_address, handler)  # type: ignoreFile "/usr/local/lib/python3.10/socketserver.py", line 452, in __init__self.server_bind()File "/usr/local/lib/python3.10/http/server.py", line 138, in server_bindsocketserver.TCPServer.server_bind(self)File "/usr/local/lib/python3.10/socketserver.py", line 466, in server_bindself.socket.bind(self.server_address)OSError: [Errno 98] Address already in use
# 运行报错:端口占用问题

分析原因:可能是之前运行的容器暴露的都是5000,且并未停止
解决:停掉之前的所有容器

# 全部停掉
docker stop 55e31feeaed7 # 此处 55e31feeaed7 为容器ID

但仍然未解决???

6 尝试解决6

因为不清楚为啥停掉了之前的所有运行中的容器,仍然显示端口已被占用,因此,决定暴露一个新的端口5001。

root@master:/home/hqc/docker_learning/plus-of-arrays# vim array-plus.py #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/12/10 上午10:14# @Author : hqc# @File : array-plus.py# @Software: PyCharmfrom flask import Flask,render_templateapp = Flask(__name__)@app.route('/')def index():list1 = [1,2,3,4,5,6]list2 = [2,3,4,5,6,7]list = [ list1[i]+list2[i] for i in range(min(len(list1),len(list2))) ]return render_template('plus.html',list = list,list1 = list1,list2 = list2)if __name__ == '__main__':app.run(port = '5001')

还是没解决???
突然发现端口好像不需要打上引号。。
修改为app.run(port = 5001)之后运行,还是显示端口被占用???哎~累了累了

7 尝试解决7

一直被占用adress所困扰,干脆把默认ip换成本机IP,端口也换到6000
可以成功构建,也可以映射端口2222后运行可以,但docker ps查看容器时没有,并且发现运行容器后就立马退出了???咱也不知道是啥问题呀

只好先改回默认adress和port

root@master:/home/hqc/docker_learning/plus-of-arrays# vim array-plus.py
root@master:/home/hqc/docker_learning/plus-of-arrays# vim Dockerfile
root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v2.4 .Sending build context to Docker daemon  5.632kBStep 1/8 : FROM python---> f48ea80eae5aStep 2/8 : RUN mkdir -p /array-plus     && mkdir -p /array-plus/templates     && pip install flask---> Using cache---> 1348fc1e170dStep 3/8 : COPY ./templates/plus.html /array-plus/templates---> Using cache---> 63a3d5c65adeStep 4/8 : COPY array-plus.py /array-plus/---> Using cache---> 01a1e208d021Step 5/8 : WORKDIR /array-plus---> Using cache---> 47a2a2cf5902Step 6/8 : EXPOSE 5000---> Using cache---> 2c373fb07eaeStep 7/8 : RUN /bin/bash -c 'echo init ok'---> Using cache---> f1bae3ef5919Step 8/8 : CMD ["python", "array-plus.py"]---> Using cache---> c93ff28fea14Successfully built c93ff28fea14Successfully tagged array-plus:v2.4
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1121:5000 array-plus:v2.4ce08f056a47127f455195fd835b79b1238ccebd010ee19247a3a33acc3be4d0f
root@master:/home/hqc/docker_learning/plus-of-arrays# docker psCONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS         PORTS                                       NAMESce08f056a471   array-plus:v2.4   "python array-plus.py"   3 seconds ago   Up 3 seconds   0.0.0.0:1121->5000/tcp, :::1121->5000/tcp   goofy_ganguly
# 仍然无法访问# 尝试直接run,不映射端口
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run array-plus:v2.4* Serving Flask app 'array-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
# 正常运行起来了!!!!

但还是无法访问

# 进入容器后运行程序
root@master:/home/hqc/docker_learning/plus-of-arrays# docker exec -it ce08f056a471 /bin/bash
root@ce08f056a471:/array-plus# python array-plus.py * Serving Flask app 'array-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: offTraceback (most recent call last):File "/array-plus/array-plus.py", line 19, in <module>app.run()File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 920, in runrun_simple(t.cast(str, host), port, self, **options)File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 1010, in run_simpleinner()File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 950, in innersrv = make_server(File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 782, in make_serverreturn ThreadedWSGIServer(File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 688, in __init__super().__init__(server_address, handler)  # type: ignoreFile "/usr/local/lib/python3.10/socketserver.py", line 452, in __init__self.server_bind()File "/usr/local/lib/python3.10/http/server.py", line 138, in server_bindsocketserver.TCPServer.server_bind(self)File "/usr/local/lib/python3.10/socketserver.py", line 466, in server_bindself.socket.bind(self.server_address)OSError: [Errno 98] Address already in use
# 仍然报老错误

分析原因:可能是dockerfile文件中已经执行了,再在容器中运行就会报该错误,因此,后续可先不用管此错误。

# 本地run是可以正常访问的
root@master:/home/hqc/docker_learning/plus-of-arrays# python array-plus.py * Serving Flask app 'array-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)127.0.0.1 - - [10/Dec/2021 18:22:59] "GET / HTTP/1.1" 200 -

提出疑问:为啥docker运行成功仍然无法访问呢??????qswl

8 尝试解决8

telnet [本机IP] [端口号]查看端口是否连通

root@master:/home/hqc/docker_learning/plus-of-arrays# telnet 172.30.117.60 1122Trying 172.30.117.60...telnet: Unable to connect to remote host: Connection refused
# 未连通

# 进入容器中进行curl访问
root@master:/home/hqc/docker_learning/plus-of-arrays# docker exec -it da5a26fc0ace /bin/bash
root@da5a26fc0ace:/array-plus# curl 127.0.0.1:5000<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>plus of array</title></head><body>list1 is :[1, 2, 3, 4, 5, 6]<br>list2 is :[2, 3, 4, 5, 6, 7]<br><br>list1 plus list2 is : [3, 5, 7, 9, 11, 13]</body></html>
# 可以正常访问# 但是以本机IP+port,被拒绝连接
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 1133:5000 array-plus:v2.420443d540f107da71d115d1ab40eeebd7edd487869fd05ee569d0b369a6ec700
root@master:/home/hqc/docker_learning/plus-of-arrays# curl 172.30.117.60:1133curl: (7) Failed to connect to 172.30.117.60 port 1133: 拒绝连接

另一种:

# 直接不映射端口运行,也是可以正常访问的
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run array-plus:v2.4* Serving Flask app 'array-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)127.0.0.1 - - [11/Dec/2021 09:17:59] "GET / HTTP/1.1" 200 -

但要注意:须新开一个终端进行curl,之前的不能关闭,关闭的话该容器会立即停止运行。

因此,我有充分理由怀疑:只是端口映射网络通信的问题,程序是一切正常可以运行的。


00 第二次构建

总感觉是多了一个html文件而出的问题,还是简单点吧。。。

root@master:/home/hqc/docker_learning/plus-of-arrays# cd ..
root@master:/home/hqc/docker_learning# mkdir json_plus
root@master:/home/hqc/docker_learning# cd json_plus/
root@master:/home/hqc/docker_learning/json_plus# vim json-plus.py#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/12/11 下午5:40# @Author : hqc# @File : json-plus.py# @Software: PyCharmfrom flask import Flask,render_template,jsonifyapp = Flask(__name__)@app.route('/')def index():list1 = [1,2,3,4,5,6]list2 = [2,3,4,5,6,7]list = [ list1[i]+list2[i] for i in range(min(len(list1),len(list2))) ]#   return render_template('plus.html',list = list,list1 = list1,list2 = list2)return jsonify(list)if __name__ == '__main__':app.run(debug=True,host='0.0.0.0')
# 改用 jsonify 省去html文件root@master:/home/hqc/docker_learning/json_plus# vim Dockerfile
root@master:/home/hqc/docker_learning/json_plus# lsDockerfile  json-plus.py
root@master:/home/hqc/docker_learning/json_plus# python json-plus.py * Serving Flask app 'json-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)127.0.0.1 - - [11/Dec/2021 20:28:57] "GET / HTTP/1.1" 200 -

本地运行访问成功:

root@master:/home/hqc/docker_learning/json_plus# docker build -t json-plus:v1.0 .
Sending build context to Docker daemon  3.584kB
Step 1/7 : FROM python---> f48ea80eae5a
Step 2/7 : RUN mkdir -p /json-plus     && pip install flask---> Running in 6a082693653b
Collecting flaskDownloading Flask-2.0.2-py3-none-any.whl (95 kB)
Collecting Werkzeug>=2.0Downloading Werkzeug-2.0.2-py3-none-any.whl (288 kB)
Collecting itsdangerous>=2.0Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting click>=7.1.2Downloading click-8.0.3-py3-none-any.whl (97 kB)
Collecting Jinja2>=3.0Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
Collecting MarkupSafe>=2.0Downloading MarkupSafe-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Installing collected packages: MarkupSafe, Werkzeug, Jinja2, itsdangerous, click, flask
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.2 click-8.0.3 flask-2.0.2 itsdangerous-2.0.1
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Removing intermediate container 6a082693653b---> 732d2f5d4c0d
Step 3/7 : COPY json-plus.py /json-plus/---> 82cb8d60ea90
Step 4/7 : WORKDIR /json-plus---> Running in 39a187aa7828
Removing intermediate container 39a187aa7828---> ee39664fcead
Step 5/7 : EXPOSE 5000---> Running in ba016287ec11
Removing intermediate container ba016287ec11---> 7e821ccd74ef
Step 6/7 : RUN /bin/bash -c 'echo init ok'---> Running in 787bc3e0b328
init ok
Removing intermediate container 787bc3e0b328---> 17f891c4ed0b
Step 7/7 : CMD ["python", "json-plus.py"]---> Running in a6db9776c7ca
Removing intermediate container a6db9776c7ca---> 7dc9d402b001
Successfully built 7dc9d402b001
Successfully tagged json-plus:v1.0
root@master:/home/hqc/docker_learning/json_plus# docker run json-plus:v1.0* Serving Flask app 'json-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [11/Dec/2021 12:34:17] "GET / HTTP/1.1" 200 -

docker运行浏览器中还是不能访问???
但进入容器中还是可以访问的。

root@master:/home/hqc# docker psCONTAINER ID   IMAGE            COMMAND                 CREATED              STATUS              PORTS      NAMES1dd28d8c2a61   json-plus:v1.0   "python json-plus.py"   About a minute ago   Up About a minute   5000/tcp   optimistic_elgamal
root@master:/home/hqc# docker exec -it 1dd28d8c2a61 /bin/bash
root@1dd28d8c2a61:/json-plus# curl http://127.0.0.1:5000/[3,5,7,9,11,13]

出现和第一次构建一毛一样的问题qswl
到底是哪出了问题呢?

01 解决(核心步骤)

对比之前的flask-hello-world的代码,发现有些不同!!!

# 修改python代码
root@master:/home/hqc/docker_learning/json_plus# vim json-plus.py #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/12/11 下午5:40# @Author : hqc# @File : json-plus.py# @Software: PyCharmfrom flask import Flask,render_template,jsonifyapp = Flask(__name__)@app.route('/')def index():list1 = [1,2,3,4,5,6]list2 = [2,3,4,5,6,7]list = [ list1[i]+list2[i] for i in range(min(len(list1),len(list2))) ]#   return render_template('plus.html',list = list,list1 = list1,list2 = list2)return jsonify(list)if __name__ == '__main__':app.run(debug=True,host='0.0.0.0')
# 修改了最后一行的debug和host,暂时不知道是哪个的作用root@master:/home/hqc/docker_learning/json_plus# vim Dockerfile
# 端口暴露保证为默认的5000# 构建镜像
root@master:/home/hqc/docker_learning/json_plus# docker build -t json-plus:v1.2 .Sending build context to Docker daemon  3.584kBStep 1/7 : FROM python---> f48ea80eae5aStep 2/7 : RUN mkdir -p /json-plus     && pip install flask---> Using cache---> 732d2f5d4c0dStep 3/7 : COPY json-plus.py /json-plus/---> 0a25ade532ebStep 4/7 : WORKDIR /json-plus---> Running in 3417773df444Removing intermediate container 3417773df444---> b288adfd98d2Step 5/7 : EXPOSE 5000---> Running in c547cd285afeRemoving intermediate container c547cd285afe---> 9f7fd3c34ec6Step 6/7 : RUN /bin/bash -c 'echo init ok'---> Running in 0281b502a454init okRemoving intermediate container 0281b502a454---> f4dd1c67120aStep 7/7 : CMD ["python", "json-plus.py"]---> Running in 2260960099dbRemoving intermediate container 2260960099db---> fab5150c7c5eSuccessfully built fab5150c7c5eSuccessfully tagged json-plus:v1.2# 直接运行
root@master:/home/hqc/docker_learning/json_plus# docker run json-plus:v1.2* Serving Flask app 'json-plus' (lazy loading)* Environment: productionWARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.* Debug mode: on* Running on all addresses.WARNING: This is a development server. Do not use it in a production deployment.* Running on http://172.17.0.2:5000/ (Press CTRL+C to quit)* Restarting with stat* Debugger is active!* Debugger PIN: 501-077-407
172.17.0.1 - - [11/Dec/2021 12:53:45] "GET / HTTP/1.1" 200 -
# 可通过http://172.17.0.2:5000/进行访问# 映射端口后运行
^Croot@master:/home/hqc/docker_learning/json_plus# docker run -d -p 1000:5000 json-plus:v1.2
29a2a2bedd9a79ffdc9b0175d25afb2730f6b4ee9dad0a98d72e0c8d6c0d4e8a


成功!!!!
以此类推,前面的应该也是这个问题。后面再测试,回家。

02 顺便解决第一次构建的问题

也是同样的问题,以下是步骤:

root@master:/home/hqc/docker_learning/plus-of-arrays# vim array-plus.py #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/12/10 上午10:14# @Author : hqc# @File : array-plus.py# @Software: PyCharmfrom flask import Flask,render_templateapp = Flask(__name__)@app.route('/')def index():list1 = [1,2,3,4,5,6]list2 = [2,3,4,5,6,7]list = [ list1[i]+list2[i] for i in range(min(len(list1),len(list2))) ]return render_template('plus.html',list = list,list1 = list1,list2 = list2)if __name__ == '__main__':app.run(debug=True,host='0.0.0.0')
# 主要也是改了最后一行# 创建
root@master:/home/hqc/docker_learning/plus-of-arrays# docker build -t array-plus:v2.5 .Sending build context to Docker daemon  5.632kBStep 1/8 : FROM python---> f48ea80eae5aStep 2/8 : RUN mkdir -p /array-plus     && mkdir -p /array-plus/templates     && pip install flask---> Using cache---> 1348fc1e170dStep 3/8 : COPY ./templates/plus.html /array-plus/templates---> Using cache---> 63a3d5c65adeStep 4/8 : COPY array-plus.py /array-plus/---> 40370d94dc7fStep 5/8 : WORKDIR /array-plus---> Running in 651c9e493a42Removing intermediate container 651c9e493a42---> 63e0109a8cb4Step 6/8 : EXPOSE 5000---> Running in 312f598ff4caRemoving intermediate container 312f598ff4ca---> fcdde5856054Step 7/8 : RUN /bin/bash -c 'echo init ok'---> Running in ae89c41bdda4init okRemoving intermediate container ae89c41bdda4---> 34d480284f2dStep 8/8 : CMD ["python", "array-plus.py"]---> Running in d6e1cfb713eaRemoving intermediate container d6e1cfb713ea---> 7f4f56bbf3c8Successfully built 7f4f56bbf3c8Successfully tagged array-plus:v2.5# 映射端口后运行
root@master:/home/hqc/docker_learning/plus-of-arrays# docker run -d -p 2000:5000 array-plus:v2.5891a8dcfe4f9aaca002b93733d0fe04dce338dbe2272c1406d8d916baf914c16

访问成功:

03 分析原因

通过寻找发现是host='0.0.0.0'的原因,和debug=True无关。
必须设置host='0.0.0.0',否则只能本地运行,无法通过外网访问。
参考的博客 讲的还比较清楚

04 一个疑问

疑问:master上运行了容器,在本机上可以正常访问,但在手机上却没法访问。

一时蒙蔽,忘了必须在同一个局域网下(同一网段)才可以访问。

第一步总结

整体上是对的,访问失败的原因主要是没有设置为可供外网访问,而不是端口映射的原因(因此,前面很多次尝试解决都是找错了方向),但那些过程也不是一无是处,正是在这些失败的过程中,对这玩意儿更加理解,一步步找到问题所在。

最关键的是01 解决(核心步骤)这步,真正解决了问题。

第二步:上传镜像到阿里云私有仓库

0 登录阿里云私有镜像仓库

root@master:/home/hqc/docker_learning/plus-of-arrays# docker login --username=errorhqc兮 registry.cn-beijing.aliyuncs.comPassword: WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

1 给镜像打一个新的标签

关键不可少,否则会push不成功

root@master:/home/hqc/docker_learning/plus-of-arrays# docker tag 7f4f56bbf3c8 registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5

注意也可通过直接在图形界面中创建

2 push到镜像仓库

root@master:/home/hqc/docker_learning/plus-of-arrays# docker push registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5The push refers to repository [registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus]f06f6fb37ea8: Pushed 7395b20bb823: Pushed bf080306b1d4: Pushed 42ce61e841fa: Mounted from hqc-k8s/ali-flask-hello-world a9b125f164c3: Mounted from hqc-k8s/ali-flask-hello-world e24045f8c247: Mounted from hqc-k8s/ali-flask-hello-world b7b662b31e70: Mounted from hqc-k8s/ali-flask-hello-world 6f5234c0aacd: Mounted from hqc-k8s/ali-flask-hello-world 8a5844586fdb: Mounted from hqc-k8s/ali-flask-hello-world a4aba4e59b40: Mounted from hqc-k8s/ali-flask-hello-world 5499f2905579: Mounted from hqc-k8s/ali-flask-hello-world a36ba9e322f7: Mounted from hqc-k8s/ali-flask-hello-world v2.5: digest: sha256:1dd85ae174eeedbaa5d370e625c6db439c4188634e58d648a6b5d30e28b9aa86 size: 2843
# push成功

3 查看

push成功!

第三步:部署到k8s

0 将集群启动

# 关闭防火墙
root@master:/home/hqc/k8s_test/array-plus# ufw disable防火墙在系统启动时自动禁用# 禁用分区
root@master:/home/hqc/k8s_test/array-plus# swapoff -a# 查看状态
root@master:/home/hqc/k8s_test/array-plus# kubectl get nodesNAME     STATUS     ROLES    AGE   VERSIONmaster   Ready      master   25d   v1.18.0node01   Ready      <none>   20d   v1.18.0

1 yaml文件创建deployment

尝试自动创建:报错

root@master:/home/hqc/k8s_test/array-plus# kubectl create deployment array-plus-deployment --image=registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5  --dry-run -o yml > array-plus-deployment.ymalW1213 20:50:23.489941    1289 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.error: unable to match a printer suitable for the output format "yml", allowed formats are: go-template,go-template-file,json,jsonpath,jsonpath-file,name,template,templatefile,yaml
# 自动创建的方法不对,启用

直接创建:

# 编写
root@master:/home/hqc/k8s_test/array-plus# vim array-plus-deployment.yamlapiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels:app: array-plus-deploymentname: array-plus-deployment
spec:replicas: 2selector:matchLabels:app: array-plus-deploymentstrategy: {}template:metadata:creationTimestamp: nulllabels:app: array-plus-deploymentspec:containers:- image: registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5name: ali-array-plusresources: {}ports:- containerPort: 5000imagePullPolicy: IfNotPresent
status: {}# 创建
root@master:/home/hqc/k8s_test/array-plus# kubectl create -f array-plus-deployment.yaml
deployment.apps/array-plus-deployment created
# 成功

2 yaml文件创建service

# 编写
root@master:/home/hqc/k8s_test/array-plus# vim array-plus-service.yamlapiVersion: v1 # 注意此处不能和deployment一样为‘apps/v1’
kind: Service
metadata:name: array-plus-deploymentlabels:app: array-plus-deployment
spec:ports:- port: 80targetPort: 5000nodePort: 30000protocol: TCPselector:app: array-plus-deploymenttype: NodePort# 创建
root@master:/home/hqc/k8s_test/array-plus# kubectl create -f array-plus-service.yaml service/array-plus-deployment created
# 成功

3 查看

root@master:/home/hqc/k8s_test/array-plus# kubectl get allNAME                                         READY   STATUS         RESTARTS   AGEpod/array-plus-deployment-55657b7c55-wfjtx   0/1     ErrImagePull   0          6m33spod/array-plus-deployment-55657b7c55-z8kx2   0/1     ErrImagePull   0          6m33spod/helloworld-deployment-79cbf4dcbb-5x6b2   1/1     Running        1          12dpod/helloworld-deployment-79cbf4dcbb-n5sps   1/1     Running        1          12dpod/helloworld-deployment-79cbf4dcbb-sr8xf   1/1     Running        1          12dpod/helloworld-deployment-79cbf4dcbb-wfh5w   1/1     Terminating    0          12dpod/nginx-f89759699-ksgcb                    1/1     Running        2          13dNAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGEservice/array-plus-deployment   NodePort    10.102.249.251   <none>        80:30000/TCP   93sservice/helloworld-deployment   NodePort    10.106.97.144    <none>        80:30002/TCP   13dservice/kubernetes              ClusterIP   10.96.0.1        <none>        443/TCP        25dservice/nginx                   NodePort    10.109.178.122   <none>        80:30650/TCP   13dNAME                                    READY   UP-TO-DATE   AVAILABLE   AGEdeployment.apps/array-plus-deployment   0/2     2            0           6m33sdeployment.apps/helloworld-deployment   3/3     3            3           12ddeployment.apps/nginx                   1/1     1            1           13dNAME                                               DESIRED   CURRENT   READY   AGEreplicaset.apps/array-plus-deployment-55657b7c55   2         2         0       6m33sreplicaset.apps/helloworld-deployment-79cbf4dcbb   3         3         3       12dreplicaset.apps/nginx-f89759699                    1         1         1       13d
# 发现并未成功

4 问题解决

结合之前的实践经验,问题应该出在节点上没法实时进行拉取,需要在各节点上事先拉取好才行。

# 登录镜像仓库
root@nodroot@node01:/hroot@nrootrootrorororoot@node01:/home/user# docker login --username=errorhqc兮 registry.cn-beijing.aliyuncs.comPassword: WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded# node本地拉取镜像
root@node01:/home/user# docker pull registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5v2.5: Pulling from hqc-k8s/ali-array-plus647acf3d48c2: Already exists b02967ef0034: Already exists e1ad2231829e: Already exists 5576ce26bf1d: Already exists a66b7f31b095: Already exists 05189b5b2762: Already exists af08e8fda0d6: Already exists 287d56f7527b: Already exists dc0580965fb6: Already exists 1cb8e8d308bd: Pull complete c68499244bc4: Pull complete 1dafd85198a4: Pull complete Digest: sha256:1dd85ae174eeedbaa5d370e625c6db439c4188634e58d648a6b5d30e28b9aa86Status: Downloaded newer image for registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5# 查看镜像
root@node01:/home/user# docker imagesREPOSITORY                                                       TAG       IMAGE ID       CREATED         SIZEregistry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus          v2.5      7f4f56bbf3c8   2 hours ago     928MB

master中再次查看:发现包括service全部正常

root@master:/home/hqc/k8s_test/array-plus# kubectl get allNAME                                         READY   STATUS        RESTARTS   AGEpod/array-plus-deployment-55657b7c55-wfjtx   1/1     Running       0          10mpod/array-plus-deployment-55657b7c55-z8kx2   1/1     Running       0          10mpod/helloworld-deployment-79cbf4dcbb-5x6b2   1/1     Running       1          12dpod/helloworld-deployment-79cbf4dcbb-n5sps   1/1     Running       1          12dpod/helloworld-deployment-79cbf4dcbb-sr8xf   1/1     Running       1          12dpod/helloworld-deployment-79cbf4dcbb-wfh5w   1/1     Terminating   0          12dpod/nginx-f89759699-ksgcb                    1/1     Running       2          13dNAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGEservice/array-plus-deployment   NodePort    10.102.249.251   <none>        80:30000/TCP   5m59sservice/helloworld-deployment   NodePort    10.106.97.144    <none>        80:30002/TCP   13dservice/kubernetes              ClusterIP   10.96.0.1        <none>        443/TCP        25dservice/nginx                   NodePort    10.109.178.122   <none>        80:30650/TCP   13dNAME                                    READY   UP-TO-DATE   AVAILABLE   AGEdeployment.apps/array-plus-deployment   2/2     2            2           10mdeployment.apps/helloworld-deployment   3/3     3            3           12ddeployment.apps/nginx                   1/1     1            1           13dNAME                                               DESIRED   CURRENT   READY   AGEreplicaset.apps/array-plus-deployment-55657b7c55   2         2         2       10mreplicaset.apps/helloworld-deployment-79cbf4dcbb   3         3         3       12dreplicaset.apps/nginx-f89759699                    1         1         1       13d

注意:无需将deployment和service删除重建,直接查看即可

5 运行验证

  1. master IP + port访问成功
  2. node IP + port访问成功
  3. dashboard中查看running成功

到此为止,完全成功!!!

dockerfile构建一个(python+flask+html)镜像 + 上传到阿里云私有仓库 + 部署到k8s---全过程相关推荐

  1. 本地打包Docker镜像上传至阿里云远程仓库(一站式脚本)

    打包镜像上传至远程仓库: 1. 本地项目为 mytest-project 2. 仓库为阿里云镜像仓库 registry.cn-beijing.aliyuncs.com/test/mytest-proj ...

  2. 如何将镜像上传至阿里云?如何从阿里云中拉取自己的镜像?

    目录 如何将制作好的镜像上传至阿里云? 一.前期准备 1.注册阿里云账户 2.登录账号 3.配置Docker加速器 4.创建镜像仓库的命名空间(私有的) 5.创建镜像仓库(创建镜像仓库时要绑定一个代码 ...

  3. 将镜像推送到阿里云私有仓库

    目录 一.将镜像推送到阿里云私有仓库 1.个人实例 2.点击个人实例 3.点击镜像仓库自行创建 4.点击创建好的仓库名称 4.1. 登录阿里云Docker Registry 4.2. 从Registr ...

  4. docker镜像上传到阿里云

    说明:文章只写了操作步骤.详情请参见b站尚硅谷 有时间的朋友可以看看 一.本地创建镜像(根据已有的容器进行创建 该容器内可以新增一些功能,如:yum.vim等:也可以通过Dockerfile打包镜像) ...

  5. Docker使用:将镜像上传至阿里云

    0x01 注册阿里云账户 阿里云官方网站链接:https://dev.aliyun.com 0x02 登陆账户 0x03 管理Docker Hub镜像站点:配置Docker加速器 链接:https:/ ...

  6. docker中部署hadoop、zookeeper、hbase伪分布式并上传到阿里云远程仓库

    ** 背景 ** docker有一点好处就是,一次完成,处处运行,所以此次并非直接在centos系统上直接运行hadoop,而是在docker容器(container)里进行安装. (1) 首先写好d ...

  7. qduoj~前端~二次开发~打包docker镜像并上传到阿里云容器镜像仓库

    2019独角兽企业重金招聘Python工程师标准>>> 上一篇文章https://my.oschina.net/finchxu/blog/1930017记录了怎么在本地修改前端,现在 ...

  8. vue.js — 安装Webpake创建一个完整的项目并上传至码云

    vue.js - 安装Webpake创建一个完整的项目并上传至码云 今天总结一下之前几天学习的一整套的创建项目方法: 前提条件:已安装node.js.npm/cnpm最新版本.vue-cli. VS ...

  9. 一步步带你实现一个简单的express服务器,能让vue通过axios请求将图片上传到阿里云OSS

    文章目录 前言 一.申请阿里云OSS 二.Vue前端读取图片 三.将图片base64转成二进制文件 四.搭建express服务器 五.通过axios给服务器发送请求 六.发送图片并上传阿里云 我们首先 ...

最新文章

  1. mfc 使用画笔画线
  2. window.location.href不打开新窗口_嘿,这条微博值得一看:不登录如何访问页面
  3. Scom 2012 中的资源组(Resource Pool)
  4. Google比Baidu快(发一个无聊的帖)
  5. 17.3.13--pycharm2和3的常识问题
  6. POJ 2135Farm Tour--MCMF
  7. Java之Maven配置教程
  8. 绝了!深入分布式缓存从原理到实践技术分享,超详细
  9. 代码制作数字流星雨_js代码实现流星雨
  10. 树莓派chromium-os系统发布
  11. 1026 程序运行时间
  12. java身份证号/手机号隐藏中间几位
  13. navicat查询oracle表结构,利用Navicat Premium导出数据库表结构信息至Excel的方法
  14. 【C语言】共用体的定义与使用
  15. ubuntu 11.10使用fcitx双拼输入法
  16. vray for 3dmax分布式渲染故障疑难解答!
  17. iOS 判断系统版本
  18. 严格模式与混杂模式-如何触发这两种模式,区分它们有何意义
  19. G-dis - Mac中的Redis客户端
  20. 尚学堂Java300答案解析 第三章

热门文章

  1. 拓扑结构计算机网络结构,计算机网络的常见的七种拓扑结构
  2. 傅里叶级数、狄利克雷收敛定理、周期延拓
  3. java 腾讯地图api,腾讯地图API详解
  4. Arduino 实时时钟DS1302模块
  5. 【anaconda】彻底解决windows下anaconda3占用C盘问题(改了envs、pkgs安装路径依旧占用C盘)
  6. TM1637驱动数码管
  7. 计算机专业白色简历封面,计算机专业个人简历封面模板图
  8. linux刻录光驱是哪个好,Linux中使用mkisofs或genisoimage刻录光盘
  9. jwt鉴权(react express jsonwebtoken)
  10. win 访问linux加密硬盘分区,手把手教你使用BitLocker给win10硬盘分区加密的方法