上传文件至 /
parent
5e3ce09741
commit
883f97b905
|
|
@ -0,0 +1,451 @@
|
|||
|
||||
1.ubuntu安装Docker
|
||||
sudo apt update
|
||||
|
||||
卸载旧版本的Docker:sudo apt remove docker docker-engine docker.io
|
||||
containerd runc
|
||||
|
||||
安装Docker需要的依赖项,包括ca-certificates、curl、gnupg、lsb-
|
||||
release等:sudo apt install ca-certificates curl gnupg lsb-release
|
||||
|
||||
允许APT使用HTTPS:sudo apt-get install apt-transport-https ca-certificates
|
||||
curl software-properties-common
|
||||
|
||||
添加Docker官方GPG密钥:
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
|
||||
-
|
||||
|
||||
添加Docker软件源。以便能够安装最新版本的Docker:
|
||||
Sudo add-apt-repository "deb [arch=amd64]
|
||||
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
|
||||
安装Docker:sudo apt install docker-ce docker-ce-cli containerd.io docker-
|
||||
buildx-plugin docker-compose-plugin
|
||||
|
||||
运行docker版本命令来验证安装是否成功:docker --version。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ubuntu安装Docker Compose
|
||||
1.下载Docker Compose二进制文件:
|
||||
sudo curl -L
|
||||
"https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-
|
||||
$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
修改二进制文件的执行权限:sudo chmod +x /usr/local/bin/docker-compose
|
||||
验证安装是否成功:docker-compose --version
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
3.准备工作
|
||||
1. 新建工作目录:ubuntu@VM-16-7-ubuntu:~$ mkdir nuantong_wms
|
||||
2. 工作目录结构:
|
||||
db目录存放数据库脚本
|
||||
jar目录存放打包好的jar应用文件
|
||||
conf目录存放redis.conf和nginx.conf配置
|
||||
html\dist目录存放打包好的静态页面文件
|
||||
mysql地址需要修改成nuantong_mysql ;项目名-mysql
|
||||
redis地址需要修改成nuantong-redis;项目名-redis
|
||||
[pic]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4.nginx.conf文件
|
||||
worker_processes 1;
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
gzip on;
|
||||
gzip_static on;
|
||||
gzip_buffers 4 16k;
|
||||
gzip_comp_level 5;
|
||||
gzip_types text/plain application/javascript text/css
|
||||
application/xml text/javascript application/x-httpd-php image/jpeg
|
||||
image/gif image/png;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
root /home/nuantong/projects/nuantong-ui;#nginx-
|
||||
dockerfile挂载目录
|
||||
try_files $uri $uri/ /index.html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
location /prod-api/{
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://nuantong-server:8010/;#nuantong-
|
||||
server为.yml里的服务名
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
}
|
||||
}
|
||||
5.redis.conf文件
|
||||
#解除本地限制 注释bind 127.0.0.1
|
||||
#bind 127.0.0.1
|
||||
|
||||
#设置密码
|
||||
requirepass 123456
|
||||
|
||||
#
|
||||
服务器运行模式,Redis以守护进程方式运行,默认为no,改为yes意为以守护进程方式启
|
||||
动,可后台运行,除非kill进程,改为yes会使配置文件方式启动redis失败,如果后面
|
||||
redis启动失败,就将这个注释掉
|
||||
daemonize no
|
||||
|
||||
#默认为no,redis持久化,可以改为yes
|
||||
appendonly yes
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
打包
|
||||
修改后台配置文件,修改MySQL地址为和Redis地址为 云服务器IP
|
||||
|
||||
[pic]
|
||||
[pic]
|
||||
|
||||
后端打包:maven→install→youchain-system-2.6.jar
|
||||
|
||||
前端打包:
|
||||
npm run build:prod
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mysql-dockerfile文件
|
||||
# 基础镜像
|
||||
FROM mysql:5.7
|
||||
# author
|
||||
MAINTAINER nuantong
|
||||
|
||||
# 执行sql脚本
|
||||
ADD ./db/*.sql /docker-entrypoint-initdb.d/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nginx-dockerfile文件
|
||||
# 基础镜像
|
||||
FROM nginx
|
||||
# author
|
||||
MAINTAINER nuantong
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/nuantong/projects/nuantong-ui
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/nuantong/projects/nuantong-ui
|
||||
# 指定路径
|
||||
WORKDIR /home/nuantong/projects/nuantong-ui
|
||||
# 复制conf文件到路径
|
||||
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
|
||||
# 复制html文件到路径
|
||||
COPY ./html/dist /home/nuantong/projects/nuantong-ui
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
redis-dockerfile文件
|
||||
# 基础镜像
|
||||
FROM redis
|
||||
# author
|
||||
MAINTAINER nuantong
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/nuantong/redis
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/nuantong/redis
|
||||
# 指定路径
|
||||
WORKDIR /home/nuantong/redis
|
||||
# 复制conf文件到路径
|
||||
COPY ./conf/redis.conf /home/nuantong/redis/redis.conf
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nuantong-dockerfile文件
|
||||
# 基础镜像
|
||||
FROM openjdk:8
|
||||
# author
|
||||
MAINTAINER nuantong
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/nuantong/jar
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/nuantong/jar
|
||||
# 指定路径
|
||||
WORKDIR /home/nuantong/jar
|
||||
# 复制jar文件到路径
|
||||
COPY ./jar/*.jar /home/nuantong/jar/nuantong.jar
|
||||
# 启动应用
|
||||
ENTRYPOINT ["java","-jar","nuantong.jar"]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
docker-compose.yml文件
|
||||
version : '3'
|
||||
services:
|
||||
nuantong-mysql:
|
||||
container_name: nuantong-mysql
|
||||
image: mysql:5.7
|
||||
build:
|
||||
context: .
|
||||
dockerfile: mysql-dockerfile
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- ./mysql/conf:/etc/mysql/conf.d
|
||||
- ./mysql/logs:/logs
|
||||
- ./mysql/data:/var/lib/mysql
|
||||
command: [
|
||||
'mysqld',
|
||||
'--innodb-buffer-pool-size=80M',
|
||||
'--character-set-server=utf8mb4',
|
||||
'--collation-server=utf8mb4_unicode_ci',
|
||||
'--default-time-zone=+8:00',
|
||||
'--lower-case-table-names=1'
|
||||
]
|
||||
environment:
|
||||
MYSQL_DATABASE: 'hefeihvac_wms'#数据库名
|
||||
MYSQL_ROOT_PASSWORD: Youchain@56 #数据库root用户密码
|
||||
nuantong-redis:
|
||||
container_name: nuantong-redis
|
||||
image: redis
|
||||
build:
|
||||
context: .
|
||||
dockerfile: redis-dockerfile
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- ./conf/redis.conf:/home/nuantong/redis/redis.conf
|
||||
- ./redis/data:/data
|
||||
command: redis-server /home/nuantong/redis/redis.conf
|
||||
nuantong-nginx:
|
||||
container_name: nuantong-nginx
|
||||
image: nginx
|
||||
build:
|
||||
context: .
|
||||
dockerfile: nginx-dockerfile
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- ./html/dist:/home/nuantong/projects/nuantong-ui
|
||||
- ./conf/nginx.conf:/etc/nginx/nginx.conf
|
||||
- ./nginx/logs:/var/log/nginx
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
depends_on:
|
||||
- nuantong-server
|
||||
links:
|
||||
- nuantong-server
|
||||
nuantong-server:
|
||||
container_name: nuantong-server
|
||||
build:
|
||||
context: .
|
||||
dockerfile: nuantong-dockerfile
|
||||
ports:
|
||||
- "8010:8010"
|
||||
volumes:
|
||||
- ./nuantong/logs:/home/nuantong/logs
|
||||
- ./nuantong/uploadPath:/home/nuantong/uploadPath
|
||||
depends_on:
|
||||
- nuantong-mysql
|
||||
- nuantong-redis
|
||||
links:
|
||||
- nuantong-mysql
|
||||
- nuantong-redis
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
启动常用命令
|
||||
sudo systemctl start docker //启动容器
|
||||
sudo systemctl restart docker //重启容器
|
||||
sudo systemctl stop docker //停止容器
|
||||
sudo docker exec -it nuantong-server bash //进入容器:nuantong-server容器名
|
||||
sudo docker-compose build //构建docker服务
|
||||
sudo docker-compose up -d //启动所有docker容器
|
||||
sudo docker ps //查看容器
|
||||
sudo docker-compose logs nuantong-server //查服务日志;nuantong-
|
||||
server:容器名
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Docker异常
|
||||
docker build 项目出现 max depth exceeded时,执行以下代码:
|
||||
1.docker system prune -a (不推荐)
|
||||
2.Dockerfile中去掉COPY、RUN相关的命令,所需文件采用-v
|
||||
命令挂载文件夹的方式实现(推荐)
|
||||
Loading…
Reference in New Issue