Docker 常用镜像

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


一、docker-compose.yml

version: '3.7'
volumes:
  data: ./data # 镜像中对 data 的映射
  config: ./config # 镜像 中 对 config 的映射
services:
#  mysql
  mysql:
    image: mysql:latest    # 从 docker hub 中 pull 最新的 redis image
    container_name: mysql  # docker 中的容器名称
    environment:
      - TZ=Asia/Shanghai   # 设置时区
      - MYSQL_ROOT_PASSWORD=123456   # 初始密码
    ports:  # 对外映射的端口,占用容器内的 6379,本机的26379,不想对外暴漏时,可以省略
      - "3306:3306"
    networks:
      - backend
    volumes:
      - data:/var/lib/mysql

# redis
  redis:
    image: redis:latest
    container_name: redis
    volumes:
      - data:/data
    ports:
      - "6379:6379"
    networks:
      - backend
    environment:
      - TZ=Asia/Shanghai

# redis UI
  redisinsight:
    image: redislabs/redisinsight:latest
    container_name: redisinsight
    volumes:
      - data:/data
    ports:
      - "38001:8001"
    networks:
      - backend
    environment:
      - TZ=Asia/Shanghai

# rabbitmq
  rabbitmq:
    image: rabbitmq:latest
    container_name: rabbitmq
    ports:
      - "5672:5672"
    networks:
      - backend
    environment:
      - TZ=Asia/Shanghai
      - RABBITMQ_DEFAULT_USER=user
      - RABBITMQ_DEFAULT_PASS=password
    restart: unless-stopped

# nginx
  nginx:
    image: nginx
    container_name: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "28080:80"
    networks:
      - backend
    restart: unless-stopped

# kurento 可用于实时通信 web RPC
  kurento:
    image: kurento/kurento-media-server:latest
    container_name: kurento-server
    ports:
      - "38888:8888"
      - "35000-35050:5000-5050/udp"
    networks:
      - backend
    environment:
      - TZ=Asia/Shanghai
      - KMS_MIN_PORT=5000
      - KMS_MAX_PORT=5050

networks:
  backend:
    name: tools

二、nginx.conf

默认配置

user  nginx; #设置nginx服务的系统使用用户
worker_processes  1; #工作进程数

error_log  /var/log/nginx/error.log warn; #nginx的错误日志
pid        /var/run/nginx.pid; #nginx启动时候的pid

events {
    worker_connections  1024; #每个进程允许的最大连接数
}

http { #http请求配置,一个http可以包含多个server

    #定义 Content-Type
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    #日志格式 此处main与access_log中的main对应
    #$remote_addr:客户端地址
    #$remote_user:http客户端请求nginx认证的用户名,默认不开启认证模块,不会记录
    #$timelocal:nginx的时间
    #$request:请求method + 路由 + http协议版本
    #status:http reponse 状态码
    #body_bytes_sent:response body的大小
    #$http_referer:referer头信息参数,表示上级页面
    #$http_user_agent:user-agent头信息参数,客户端信息
    #$http_x_forwarded_for:x-forwarded-for头信息参数
    log_format  main  '$http_user_agent' '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #访问日志,后面的main表示使用log_format中的main格式记录到access.log中
    access_log  /var/log/nginx/access.log  main;

    #nginx的一大优势,高效率文件传输
    sendfile        on;
    #tcp_nopush     on;

    #客户端与服务端的超时时间,单位秒
    keepalive_timeout  65;

    #gzip  on;
    server { #http服务,一个server可以配置多个location
        listen       80; #服务监听端口
        server_name  localhost; #主机名、域名

        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            root   /usr/share/nginx/html; #页面存放目录
            index  index.html index.htm; #默认页面
        }

        #error_page  404              /404.html;

        # 将500 502 503 504的错误页面重定向到 /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html { #匹配error_page指定的页面路径
            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;
        #}
    }
    include /etc/nginx/conf.d/*.conf;
}

三、使用

将以上两个文件放在同一文件夹下

注意文件夹不能放在含中午的路径中

# build image 并 生成容器,启动 image
docker compose up -d 		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值