docker 启动简单的开发环境(mysql, redis, etcd)

docker开启容器分为两种,一种是命令启动,一种是用yaml启动

本片文章用到的是yaml启动

以下是启动脚本:env.yaml

version: "3"
services:
  jump_etcd:
    container_name: jump_etcd
    image: bitnami/etcd:3
    privileged: true
    volumes:
    - "$CHDIR/etcd_data:/opt/bitnami/etcd/data"
    environment:
      - "ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379"
      - "ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379"
      - "ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380"
      - "ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380"
      - "ALLOW_NONE_AUTHENTICATION=yes"
      - "ETCD_INITIAL_CLUSTER=node1=http://0.0.0.0:2380"
      - "ETCD_NAME=node1"
      - "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
    ports:
      - "2379:2379"
      - "2380:2380"

  jump_redis:
    container_name: jump_redis
    image: harbor.corp.sdo.com/library/redis:6.0
    volumes:
      - "$CHDIR/redis_data:/data"
    ports:
      - "16379:6379"
    command:
      "redis-server --appendonly yes"
  
  jump_mysql:
      container_name: jump_mysql
      image: harbor.corp.sdo.com/library/mysql:8.0
      environment:
        - "MYSQL_ROOT_PASSWORD=123456"
        - "MYSQL_DATABASE=jump"
      volumes:
        - "./my.cnf:/etc/mysql/my.cnf"
      ports:
        - "13306:3306"

container_name:是容器的名字

image:是启动容器的镜像,如果本地没有该镜像,则会到远程镜像库里去下载,安装不同版本的都只需要改这个参数就可以了

在启动mysql时用到了配置my.cnf,这个可以在网上直接down一个,放在yaml相同的目录

我这里提供了一个my.cnf,大家可以copy使用

以下是my.cnf文档

# Copyright (c) 2017, 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 as published by
# the Free Software Foundation; version 2 of the License.
#
# 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 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
secure-file-priv= NULL
skip_ssl
default_authentication_plugin = mysql_native_password
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/

docker的启动yaml启动好后,需要用命令执行yaml

启动:docker-compose -f env.yaml up -d

关闭:docker-compose -f env.yaml down

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值