docker常用容器启动命令
- mysql启动
- redis启动
- nginx配置文件&启动
mysql启动
docker run -itd --name mysql-test --restart=always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
redis启动
docker run -itd --name redis-test --restart=always -p 6379:6379 redis
nginx配置文件&启动
备注: 当前是把配置文件、日志、HTML资源文件夹映射到宿主机的,所以要先创建对应的目录和配置文件nginx.conf
mkdir -p /app/nginx/html mkdir -p /app/nginx/logs mkdir -p /app/nginx/conf cd /app/nginx/conf vi nginx.conf # 将配置文件内容粘贴到配置文件中,然后保存并退出
nginx.conf配置文件内容模板如下:
user root; worker_processes 2; #error_log /var/log/nginx/error.log; #pid /var/log/nginx/nginx.pid; events { worker_connections 1024; } http { include mime.types; #default_type application/octet-stream; default_type application/javascript; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent"'; #access_log /var/log/nginx/access.log main; sendfile on; tcp_nodelay on; keepalive_timeout 65; gzip on; server { listen 80; server_name localhost; location / { root /html/; try_files $uri $uri/ /index.html; index index.html index.htm; } location /prod-api/ { proxy_pass http://192.168.3.207:8080/; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; if ($request_method = 'OPTIONS') { return 204; } } error_page 500 501 502 503 504 /50x.html; location = /50x.html { root /html; } } }
nginx启动命令
docker run -itd --name nginx-test --restart=always -p 80:80 -v /app/nginx/html:/html -v /app/nginx/logs:/var/log/nginx -v /app/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime nginx
还没有评论,来说两句吧...