# Docker
# Docker windows desktop 安装
下载最新版,安装对应的 linux 镜像
# Docker desktop 目录修改
先创建一个文件夹叫 docker
script | |
| wsl --export docker-desktop "D:\\docker\\docker-desktop.tar" |
| |
| wsl --unregister docker-desktop |
| |
| wsl --import docker-desktop "D:\\docker\\wsl" "D:\\docker\\docker-desktop.tar" --version 2 |
| |
| |
| wsl --export docker-desktop-data "D:\\docker\\docker-desktop-data.tar" |
| |
| wsl --unregister docker-desktop-data |
| |
| wsl --import docker-desktop-data "D:\\docker\\wsl" "D:\\docker\\docker-desktop-data.tar" --version 2 |
# docker 部署 demo
# python 项目打包
# rquirements 生成
| |
| python3 -m pip install pipreqs |
| |
| pipreqs . --encoding=utf8 --force |
# dockerfile 生成
| touch Dockerfile.dockerfile |
然后在里面写入
| |
| |
| FROM python:3.8-slim-buster |
| |
| WORKDIR /app |
| |
| COPY requirements.txt requirements.txt |
| RUN pip3 install -r requirements.txt |
| |
| COPY . . |
| |
| CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] |
然后运行
script | docker build --tag python-docker . |
# vue 项目打包 (按照官网的搞)
新建一个目录 存放 disk 文件夹,在该文件夹下创建 Dockerfile 文件以及 nginx.conf
Dockerfile:
| user nginx; |
| worker_processes 1; |
| error_log /var/log/nginx/error.log warn; |
| pid /var/run/nginx.pid; |
| events { |
| worker_connections 1024; |
| } |
| http { |
| include /etc/nginx/mime.types; |
| default_type application/octet-stream; |
| log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| '$status $body_bytes_sent "$http_referer" ' |
| '"$http_user_agent" "$http_x_forwarded_for"'; |
| access_log /var/log/nginx/access.log main; |
| sendfile on; |
| keepalive_timeout 65; |
| server { |
| listen 80; |
| server_name localhost; |
| location / { |
| root /vue-docker; |
| index index.html; |
| try_files $uri $uri/ /index.html; |
| } |
| error_page 500 502 503 504 /50x.html; |
| location = /50x.html { |
| root /usr/share/nginx/html; |
| } |
| } |
| } |
nginx.conf
| FROM nginx |
| |
| EXPOSE 80 |
| |
| COPY /dist /usr/share/nginx/html |
| |
| ENTRYPOINT nginx -g "daemon off;" |
然后直接运行
script | |
| docker build -t nginx-image . |
script | |
| |
| |
| |
| docker run -p 8099:80 -d --name vue-project nginx-image |
# 容器推送
# 本地打包为 tar 然后直接上传
script | |
| docker save -o centos.tar centos |
| |
| |
| docker load -i centos.tar |
# 运行
script | |
| docker run -d -p 5000:5000 --name rest-server python-docker |