docker 启动简单的开发环境mysql redis etcd
终极管理员 知识笔记 84阅读
docker开启容器分为两种一种是命令启动一种是用yaml启动
本片文章用到的是yaml启动

以下是启动脚本env.yaml
version: 3services: 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 - ETCD_LISTEN_CLIENT_URLS - ETCD_LISTEN_PEER_URLS - ETCD_INITIAL_ADVERTISE_PEER_URLS - ALLOW_NONE_AUTHENTICATIONyes - ETCD_INITIAL_CLUSTERnode1 - ETCD_NAMEnode1 - 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_PASSWORD123456 - MYSQL_DATABASEjump 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# /var/run/mysqld/mysqld.pidsocket /var/run/mysqld/mysqld.sockdatadir /var/lib/mysqlsecure-file-priv NULLskip_ssldefault_authentication_plugin mysql_native_password# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links0# 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
标签: