1.docker 部署vue
docker 安装 nginx的镜像
niginx 配置文件
nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 9090;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#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 html;
}
# 配置代理,解决跨域问题
location ^~ /api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://X.X.X.X:7777/;
}
# 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
docker 安装nginx ,并运行挂载主机
1.创建挂载目录
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
2.执行容器
# 生成容器
docker run --name= nginx -p 9001:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /home/nginx/
3.挂载完成后删除重启
# 直接执行docker rm nginx或者以容器id方式关闭容器
# 找到nginx对应的容器id
docker ps -a
# 关闭该容器
docker stop nginx
# 删除该容器
docker rm nginx
# 删除正在运行的nginx容器
docker rm -f nginx
4.重启
docker run \
-p 9002:80 \
--name nginx \
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/log:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-d nginx:latest
启动后可以发现nginx容器是功能减少版的linux,其中丢失了vi等函数,所以只能通过挂载的形式,让宿主机影响容器.
配值dockerfile
# 基础镜像使用Nginx
FROM nginx
# 作者
MAINTAINER hou
# 添加时区环境变量,亚洲,上海
ENV TimeZone=Asia/Shanghai
# 使用软连接,并且将时区配置覆盖/etc/timezone
RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone
# 将前端dist文件中的内容复制到nginx目录
COPY dist/ /etc/nginx/html/
# 覆盖镜像的Nginx配置
COPY nginx.conf /etc/nginx/nginx.conf
#输出完成
RUN echo 'echo init ok!!'
-
然后build 为镜像 docker build -f (当前路径)./xxdockerfile -t 镜像名 .
docker build -f ./Dockerfile -t qianduanimage .
-
docker run -id --name=project-vue -p 9876:9876 qianduanimage(镜像)
2.docker 部署springboot项目
1.需求:
定义dockerfile,发布springboot 项目
实现步骤:
和你的后盾jar包同一目录新建Dockerfile
FROM java:8
MAINTAINER hou
ADD springboot.jar app.jar
CMD java -jar app.jar
- 定义父镜像:
FROM java:8
- 定义作者信息:
MAINTAINER hou <www.crisp077.xyz>
- 将jar包添加到容器且重命名:
ADD springboot.jar app.jar
- 定义容器启动执行的命令:
CMD java -jar app.jar
- 通过dockerfile 构建镜像:
docker build -f dockerfile文件路径 -t 镜像名称:版本
.(注意这里有个点) - 构建
docker build -f ./Dockerfile -t app .
- 运行
docker run -id --name=houuduan -p 80:800 镜像名字
其中
-
-p 外接口:镜像接口 docker 这里指的是项目80端口 外映射到服务器
-
80:映射到的外联端口
-
800:镜像项目的端口