一、后端项目
1.打包应用
mvn clean package -DskipTests2、新建dockerfile文件

#基础镜像
FROM openjdk:8
#工作空间
WORKDIR  /opt
#复制文件
COPY wms-app-1.0-SNAPSHOT.jar app.jar
#配置容器暴漏的端口
EXPOSE 8080
RUN ls
#强制执行命令
ENTRYPOINT [ "java","-jar","app.jar" ]3.打包镜像(.代表当前目录,输入命令时要进入文件所在目录)
docker build -t mall:v1 . 4.测试运行
  4.测试运行
 
--rm 代表退出之后,容器自动删除
docker run -it --rm beimao:v1
5.阿里云免费私仓
可以把项目发布到阿里云私仓
容器镜像服务 (aliyun.com)
进入网站,点击选择创建个人实例,然后点击创建镜像仓库,填写仓库信息,点击下一步
选择本地仓库,点击创建镜像仓库

 根据操作指南进行推送和拉取
根据操作指南进行推送和拉取
例:推送

 二、前端项目
 二、前端项目
 
1 、编译打包
npm run build

将打包好的文件放到在opt目录下的新建wms_web/html目录中
 
 
2、前端项目 nginx的配置文件default.conf 和 dockerfile

(1)新建default.conf文件
可以使用以下命令进入nginx容器中查看文件,复制原本的进行修改

例:
upstream wms-app{
    server 192.168.11.99:3999;
}
server {
    listen 80;
    server_name  localhost;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;#解决单页面找不到路径问题 404
    }
    location /api/ {
        proxy_pass http://wms-app;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
(2)新建dockerfile
FROM nginx
COPY html /usr/share/nginx/html
RUN rm -rf /etc/nginx/conf.d/default.conf
COPY default.conf /etc/nginx/conf.d/default.conf1.root:设置静态根目录为 /usr/share/nginx/html
2. index:设置目录的默认文件为 index.html 、index.htm、index.php
3. try_files:设置文件查找规则为 $uri $uri/ /index.html。即3个规则,先从 $uri 查找,再从 u r i / 目录中查找,最后查找 / i n d e x . h t m l 。
3 、构建镜像
docker build -t web:v1 . 
 
4、运行
如果运行时报错,更改了配置文件需要重新build构建镜像,否则使用原来的会继续报错
docker  run -it -p 8086:80  web:v1 结果:可在本地浏览器中访问
结果:可在本地浏览器中访问




















