docker-compose语法
mysql部署
version: '3' services: common_mysql: restart: always image: mysql:8.0.20 container_name: common_mysql #设置编码 字符集 远程登录 # command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password #--lower_case_table_names=1 忽略表大小写 command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-authentication-plugin=mysql_native_password volumes: - ./mydir:/mydir - ./datadir:/var/lib/mysql - ./conf/my.cnf:/etc/my.cnf environment: TZ: Asia/Shanghai MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: free MYSQL_USER: free MYSQL_PASSWORD: free networks: - custom_net ports: - 3306:3306 networks: custom_net: #内部网络 external: name: common_net #外部网络
nexus
version: '3' services: common_nexus3: image: sonatype/nexus3 container_name: common_nexus3 restart: always volumes: - ./nexus-data:/nexus-data networks: - custom_net ports: - 8081:8081 environment: NEXUS_CONTEXT: nexus networks: custom_net: #内部网络 external: name: common_net #外部网络 #访问路由http://ip:8081/nexus
redis
version: '3' services: redis: hostname: redis image: redis:5.0.4 container_name: common_redis restart: always command: redis-server /etc/redis.conf # 启动redis命令 networks: - custom_net environment: - TZ=Asia/Shanghai volumes: #win10注释 - /etc/localtime:/etc/localtime:ro # 设置容器时区与宿主机保持一致 - ./redis/data:/data - ./redis/redis.conf:/etc/redis.conf ports: - "6379:6379" networks: custom_net: #内部网络 external: name: common_net #外部网络
nginx
version: '3' services: nginx: image: nginx:stable-alpine #image_2: nginx:1.19.1-alpine container_name: nginx-alpine restart: always privileged: true environment: - TZ=Asia/Shanghai ports: - 8080:80 - 80:80 - 443:443 volumes: - /etc/localtime:/etc/localtime:ro #- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro - ./conf.d:/etc/nginx/conf.d - ./log:/var/log/nginx - ./dist:/opt/dist:ro
gogs部署
version: '3' services: gogs: image: gogs/gogs ports: - "10022:22" - "3000:3000" volumes: - ./data/gogs:/data depends_on: - mysql mysql: image: mysql:5.7.16 container_name: gogs_mysql volumes: - ./gogs/mysql:/var/lib/mysql ports: - 3308:3306 command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: gogs MYSQL_USER: gogs MYSQL_PASSWORD: gogs TZ: Asia/Shanghai
drone部署
# ip:xxxxxxxx ci-build ### docker-compose.yml #测试成功,附带mysql version: "2.1" services: drone-server: image: drone/drone:1 ports: - 443:443 - 80:80 volumes: - /var/lib/drone:/data restart: always depends_on: - mysql environment: - DRONE_DATABASE_DATASOURCE=/var/lib/drone/drone.sqlite - DRONE_DATABASE_DRIVER=sqlite3 - DRONE_DATABASE_DRIVER=mysql - DRONE_DATABASE_DATASOURCE=root:root@tcp(ci_mysql:3306)/drone?parseTime=true - DRONE_AGENTS_ENABLED=true - DRONE_LOGS_DEBUG=true - DRONE_GIT_ALWAYS_AUTH=false - DRONE_GITLAB_SERVER=http://192.168.10.54:8083/ # gitlab服务器地址 - DRONE_GITLAB_CLIENT_ID=ea11d55c67c47043d409d90a14fce1043f82231b45809b30a3f5bc0cee711bf7 # application ID - DRONE_GITLAB_CLIENT_SECRET=b4846990c58ffb5ce494e697a1c09225edf3025c5275ee527b32157a0e1b2e83 # Secret - DRONE_RPC_SECRET=e349d16fa70e27bdd1043c1ec3d83478 # 为server和agent设置一个统一识别码 随便输,但必须前后一致 - DRONE_USER_CREATE=username:root,admin:true # 为drone的settings添加Trued username是gitlab用户名 admin默认为true - DRONE_RUNNER_CAPACITY=3 - DRONE_SERVER_HOST=192.168.10.202 # drone服务器地址 - DRONE_SERVER_PROTO=http - DRONE_TLS_AUTOCERT=false networks: - ci_net drone-agent: image: drone/drone-runner-docker:1 restart: always depends_on: - drone-server volumes: - /var/run/docker.sock:/var/run/docker.sock:rw environment: - DRONE_RPC_PROTO=http - DRONE_RPC_HOST=192.168.10.202 # 服务器地址 - DRONE_RPC_SECRET=e349d16fa70e27bdd1043c1ec3d83478 - DRONE_RUNNER_CAPACITY=3 - DRONE_RUNNER_NAME=ip # runner名字 默认为服务器ip - DRONE_LOGS_TRACE=true networks: - ci_net mysql: restart: always image: mysql:5.7.16 container_name: ci_mysql command: --default-authentication-plugin=mysql_native_password #这行代码解决无法访问的问题 volumes: - ./mydir:/mydir - ./datadir:/var/lib/mysql - ./conf/my.cnf:/etc/my.cnf # 数据库还原目录 可将需要还原的sql文件放在这里 - /docker/mysql/source:/docker-entrypoint-initdb.d environment: - "MYSQL_ROOT_PASSWORD=root" - "MYSQL_DATABASE=drone" - "TZ=Asia/Shanghai" networks: - ci_net ports: - 3307:3306 networks: ci_net: driver: bridge
gitlab(已验证)
version: '3.4' services: gitlab: image: store/gitlab/gitlab-ce:11.10.4-ce.0 container_name: gitlab restart: always hostname: 192.168.10.149 environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.10.149' gitlab_rails['gitlab_shell_ssh_port'] = 8022 # 邮箱配置 gitlab_rails['gitlab_email_from'] = 'hongyikeji2020@126.com' gitlab_rails['gitlab_email_display_name'] = '虹蚁科技' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = 'smtp.126.com' gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "123020@126.com" gitlab_rails['smtp_password'] = "LLUSGLWXECBBIIGZ" gitlab_rails['smtp_domain'] = 'smtp.126.com' gitlab_rails['smtp_openssl_verify_mode'] = 'none' gitlab_rails['gitlab_email_reply_to'] = 'hongyikeji2020@126.com' gitlab_rails['gitlab_email_enabled'] = true gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true ports: - "8022:22" - "80:80" volumes: - ./gitlab/config:/etc/gitlab - ./gitlab/logs:/var/log/gitlab - ./gitlab/data:/var/opt/gitlab privileged: true
指定文件构建容器
docker-compose -f docker-compose.es.yml up
docker-compose用例参考
1.
version: "3" services: # 指定服务名称 #服务注册与发现中心 simonEureka: image: simon/eureka-server:2.0.1-SNAPSHOT hostname: simonEureka ports: - "8100:8100" #配置中心 simonConfig: image: simon/config-server:2.0.1-SNAPSHOT hostname: simonConfig ports: - "8101:8101" depends_on: - simonEureka # always – 不管退出状态码是什么始终重启容器。当指定always时,docker daemon将无限次数地重启容器。容器也会在daemon启动时尝试重启,不管容器当时的状态如何。 # no – 容器退出时不要自动重启。这个是默认值。 # on-failure[:max-retries] – 只在容器以非0状态码退出时重启。可选的,可以退出docker daemon尝试重启容器的次数。 # unless-stopped - 不管退出状态码是什么始终重启容器,不过当daemon启动时,如果容器之前已经为停止状态,不要尝试启动它。 restart: always #路由网关 apigateway: image: simon/apigateway:2.0.1-SNAPSHOT ports: - "8102:8102" depends_on: - simonEureka - simonConfig restart: always #监控平台 admin: image: simon/admin:2.0.1-SNAPSHOT ports: - "8103:8103" depends_on: - simonEureka - simonConfig restart: always --------------------- 作者:AaronSimon 来源:CSDN 原文:https://blog.csdn.net/aaronsimon/article/details/82711610 版权声明:本文为博主原创文章,转载请附上博文链接!
2.