赞
踩
背景:苍穹外卖项目,部署到Docker中,实现容器化访问
docker pull nginx
mkdir conf
mkdir html
mkdir log
docker cp nginx:/usr/share/nginx/html /Users/xxx/xxxx/xxx/nginx
docker run --rm nginx cat /etc/nginx/nginx.conf > /Users/xx x/xxx/xxx/xxx/conf/nginx.conf
docker cp /Users/xxx/xxx/苍穹外卖/资料/day01/前端运行环境/nginx-1.20.2/html/sky mynginx:/usr/share/nginx/html
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { upstream webservers{ server 127.0.0.1:8080 weight=90 ; #server 127.0.0.1:8088 weight=10 ; } server { listen 80;#容器内监听的端口 server_name localhost; location / { #root html; root /usr/share/nginx/html/sky; index index.html index.htm; } 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-Forwarded-Proto $scheme; proxy_set_header Content-Type "application/json"; #proxy_pass http://host.docker.internal:80;#这里访问的是宿主机的端口 proxy_pass http://host.docker.internal:9001/admin/; #proxy_pass http://webservers/admin/; } # 反向代理,处理管理端发送的请求 # 反向代理,处理用户端发送的请求 location /user/ { proxy_pass http://webservers/user/; } } 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; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
docker run --name mynginx -v /Users/xxx/xxx/xxx/xxx/html:/usr/share/nginx/html -v /Users/xxx/xxx/xxx/xxx/conf/nginx.conf:/etc/nginx/nginx.conf -v /Users/xxx/xxx/xxx/xxx/logs:/var/log/nginx -p 9000:80 -d nginx
前端访问localhost:9000
mvn clean package
# 使用官方的OpenJDK作为基础镜像
FROM openjdk:17-jdk-alpine
# 设置应用程序的工作目录
WORKDIR /app
# 将生成的JAR文件复制到容器中
COPY sky-server/target/sky-server-1.0-SNAPSHOT.jar app.jar
# 暴露容器的端口
EXPOSE 8080
# 指定容器启动时运行的命令
ENTRYPOINT ["java", "-jar", "app.jar"]
sudo docker build -t waimai .
因为mysql和redis都在本机上,就不制作镜像打包上去,修改一下配置文件就好
sky: datasource: driver-class-name: com.mysql.cj.jdbc.Driver host: host.docker.internal port: 3306 database: sky_take_out username: root password: ### alioss: endpoint: oss-cn-beijing.aliyuncs.com access-key-id: LTAI5tBotS31uKWBjjsUKUMX access-key-secret: quRMZwBgxlRWd7BP4xkRLwT9b0BJMd bucket-name: vince1998 redis: host: host.docker.internal port: 6379 password: # database: 10
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。