docker-compose部署nginx+aspnetcore

2019-04-21  本文已影响0人  GH_12d8

1. docker-compose 安装

curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

2. aspnetcore Dockerfile

cd ~
mkdir docker_compose
cp firstmvc ~/docker_compose/firstmvc
cd ~/docker_compose/firstmvc
touch Dockerfile
vi Dockerfile
#添加基础镜像
FROM microsoft/dotnet:2.2-aspnetcore-runtime
#容器中系统的工作空间
WORKDIR /app
#设置Docker容器对外暴露端口
EXPOSE 80
#使用ENTRYPOINT ["dotnet","系统启动的dll"]
ENTRYPOINT ["dotnet","FirstCoreMvc.dll"]

3. Nginx配置文件

cd ~/docker_compose
mkdir nginx
touch proxy.conf
vi proxy.conf
upstream test {
  ip_hash;
  server firstmvc-web-1:80 weight=10;
  server firstmvc-web-2:80 weight=20;
}
server {
  listen 80;
  server_name localhost;
  location / {
    proxy_pass http://test;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

3. docker-compose.yml 配置

cd ~/docker_compose
touch docker-compose.yml
vi docker-compose.yml
version: '2.0'
services:
    firstmvc-web-1:
        container_name: mvc1
        build: ./firstmvc
        expose:
            - 80
        volumes:
            - ./firstmvc:/app
        links:
            - firstmvc-mysql
            - firstmvc-redis
            - firstmvc-mongo

    firstmvc-web-2:
        container_name: mvc2
        build: ./firstmvc
        expose:
            - 80
        volumes:
            - ./firstmvc:/app
        links:
            - firstmvc-mysql
            - firstmvc-redis
            - firstmvc-mongo

    reverse-proxy:
        image: nginx
        container_name: reverse-proxy
        links:
            - firstmvc-web-1
            - firstmvc-web-2
        ports:
            - "5000:80"
        volumes:
            - ./nginx/first_nginx.conf:/etc/nginx/conf.d/default.conf
    firstmvc-mysql:
        image: mysql:5.7.25
        container_name: firstmvc-mysql
        volumes:
            - ./mysql:/var/lib/mysql
        environment:
            - MYSQL_ROOT_PASSWORD=123456
        ports:
            - "3306:3306"
    firstmvc-redis:
        image: redis
        container_name: firstmvc-redis
        volumes:
            - ./redis/redis.conf:/etc/redis/redis.conf
            - ./redis/data:/data
        ports:
            - 6379:6379
        command: redis-server /etc/redis/redis.conf
    firstmvc-mongo:
        image: firstmvc-mongo
        restart: always
        ports:
          - 27017:27017
        volumes:
          - ./mongo/data:/data/db/
        environment: 
          MONGO_INITDB_ROOT_USERNAME: admin
          MONGO_INITDB_ROOT_PASSWORD: DoNotPeek
        privileged: true

4. redis.conf配置

bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

################################# GENERAL #####################################
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
#日志
logfile "/data/redis.log"
#数据库数量
databases 10

################################ SNAPSHOTTING  ################################
save 1 1
#save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
#数据文件目录
dir /data

################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

################################## SECURITY ###################################
#密码 redis
requirepass redis

################################### LIMITS ####################################
maxclients 10000

############################## APPEND ONLY MODE ###############################
appendonly yes
appendfilename "appendonly.aof"
# appendfsync always
appendfsync everysec
# appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

################################ LUA SCRIPTING  ###############################
lua-time-limit 5000

################################ REDIS CLUSTER  ###############################
cluster-enabled no

################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128

################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

5. docker-compose 常用命令

#启动
docker-compose up -d
#修改yml后,需要强制重建指定服务xxxxx但不重建links关联服务,然后启动
docker-compose up -d --force-recreate --no-deps xxxxx
#停止并移除容器
docker-compose down
#重启
docker-compose restart
上一篇下一篇

猜你喜欢

热点阅读