我是靠谱客的博主 懵懂水池,最近开发中收集的这篇文章主要介绍docker-compose 常用yaml 文件 配置,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

docker-compose.yaml 

java

version: "3.6"
services:
  dev-11100:
    image: java:8u111-jdk
    container_name: dev-11100
    ports:
      - 11100:8088
      - 21100:5555
    restart: always
    working_dir: /opt/app
    volumes:
      - ../app:/opt/app
      - /etc/localtime:/etc/localtime:ro
    command: java -Duser.timezone=GMT+08 -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5555 -Xms256M -Xmx512M web.jar --spring.profiles.active=dev

mysql

version: "3.6"
services:
  database:
    image: mysql:5.7.22
    container_name: database
    ports:
      - 3306:3306
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
    volumes:
      - ../datadir:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro

2020年4月29日11:18:42 新增mysql增加binlog日志配置 start

参考来源:https://blog.csdn.net/harris135/article/details/79712750

步骤

# 需要增加的内容 server-id= 内容,随机指定一个不能和其他集群中机器重名的字符串,如果只有一台机器,那就可以随便指定了

log-bin=/var/lib/mysql/mysql-bin
server-id=123456

# 创建文件夹和目录
mkdir conf.d
cd conf.d
# 编辑文件
vi mysqld.cnf

文件内容 

# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=/var/lib/mysql/mysql-bin
server-id=123456

yml文件配置

version: "3.6"
services:
  mysql:
    image: mysql:5.7
    container_name: mysql
    ports:
      - 3306:3306
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
    volumes:
      - ../datadir:/var/lib/mysql
      - ../conf.d/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf #注意文件位置,跟yml文件
      - /etc/localtime:/etc/localtime:ro
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES utf8mb4;' --innodb-flush-log-at-trx-commit=0

 

2020年4月29日11:18:42 新增mysql增加binlog日志配置 end

nginx

version: "3.6"
services:
  nginx:
    image: nginx:1.15.7
    container_name: nginx
    ports:
      - 80:80
      - 443:443
    restart: always
    volumes:
      - ../data/static:/usr/share/nginx/static
      - ../data/conf/nginx.conf:/etc/nginx/nginx.conf
      - ../data/conf.d:/etc/nginx/conf.d
      - ../data/logs:/var/log/nginx
      - ../data/cert:/etc/nginx/cert
      - /etc/localtime:/etc/localtime:ro

nginx 配置文件 conf/nginx.conf 

#user  nobody;
worker_processes  4;

events {
        worker_connections  1024;
}

http {
        include                 mime.types;
        default_type            application/octet-stream;
        client_max_body_size    20m;
        sendfile                on;
        keepalive_timeout       0;
        gzip                    on;   
        include     conf.d/*.conf;
}

conf.d/xxx.conf 

upstream xxx_web {
    server 192.168.1.15:3000 weight=1;
}

server {
    listen 80;
    server_name dev.xxx.cn;
    client_max_body_size 200m;
    
    location /dist/ {
        root /usr/share/nginx/static/dev;
    }
    # 2020年4月30日12:51:43 修改 /xxx接口代理路径 变更/xxx/
    # 代理的端口访问后端时不会在域名后两个//,可查看后端可得
    location /xxx/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://xxx_web/;
    }
}

gitlab-ce

version: "3.6"
services:
  gitlab-ce:
    image: gitlab/gitlab-ce:12.0.2-ce.0
    container_name: gitlab-ce
    hostname: 192.168.1.15
    ports:
     - "8086:80"
     - "8087:443"
     - "8088:22"
    restart: always
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        #external_url 'https://192.168.1.15:8087'
        gitlab_rails['lfs_enabled'] = true
        gitlab_rails['backup_keep_time'] = 604800
        gitlab_rails['gitlab_shell_ssh_port'] = 8088
    volumes:
     - /etc/localtime:/etc/localtime:ro
     - ../datadir/gitlab/config:/etc/gitlab
     - ../datadir/gitlab/logs:/var/log/gitlab
     - ../datadir/gitlab/data:/var/opt/gitlab

jenkins

version: "3.6"
services:
  jenkins:
    image: jenkins/jenkins:2.181
    container_name: jenkins
    user: root
    ports:
     - "8080:8080"
     - "50000:50000"
    restart: always
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock
     - ../software:/opt/software
     - /usr/bin/docker:/usr/bin/docker:ro
     - ../jenkins_home:/var/jenkins_home
     - /etc/localtime:/etc/localtime:ro

nexus

version: "3.6"
services:
  nexus:
    image: sonatype/nexus3:3.16.2
    container_name: nexus
    ports:
     - 8081:8081
    restart: always
    user: root
    volumes:
     - ../nexus-data:/nexus-data
     - /etc/localtime:/etc/localtime:ro

2019年7月2日16:33:36 新增

fastdfs

version: '3.6'

services:
  tracker:
    image: morunchang/fastdfs 
    restart: always
    container_name: tracker
    privileged: true
    # 网络模式为host,即直接使用主机的网络接口
    network_mode: "host"
    command: /bin/sh tracker.sh
  storage:
    image: morunchang/fastdfs 
    restart: always
    container_name: storage
    environment:
     - TRACKER_IP=192.168.1.15:22122
     - GROUP_NAME=storagegroup
    volumes:
    # 将本地目录映射到docker容器内的fastdfs数据存储目录,将fastdfs文件存储到主机上,以免每次重建docker容器,之前存储的文件就丢失了。
     - ../data/fast_data:/data/fast_data
    # 使docker具有root权限以读写主机上的目录
    privileged: true
    # 网络模式为host,即直接使用主机的网络接口
    network_mode: "host"
    command: /bin/sh storage.sh

frpc

version: "3.6"
services:
  frpc:
    image: centos:7
    container_name: frpc
    restart: always
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /opt/frpc:/opt/frpc
    command: /opt/frpc/frpc -c /opt/frpc/frpc.ini

 

 

最后

以上就是懵懂水池为你收集整理的docker-compose 常用yaml 文件 配置的全部内容,希望文章能够帮你解决docker-compose 常用yaml 文件 配置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部