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


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

    本片文章用到的是yaml启动

    以下是启动脚本:env.yaml

    1. version: "3"
    2. services:
    3. jump_etcd:
    4. container_name: jump_etcd
    5. image: bitnami/etcd:3
    6. privileged: true
    7. volumes:
    8. - "$CHDIR/etcd_data:/opt/bitnami/etcd/data"
    9. environment:
    10. - "ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379"
    11. - "ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379"
    12. - "ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380"
    13. - "ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380"
    14. - "ALLOW_NONE_AUTHENTICATION=yes"
    15. - "ETCD_INITIAL_CLUSTER=node1=http://0.0.0.0:2380"
    16. - "ETCD_NAME=node1"
    17. - "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
    18. ports:
    19. - "2379:2379"
    20. - "2380:2380"
    21. jump_redis:
    22. container_name: jump_redis
    23. image: harbor.corp.sdo.com/library/redis:6.0
    24. volumes:
    25. - "$CHDIR/redis_data:/data"
    26. ports:
    27. - "16379:6379"
    28. command:
    29. "redis-server --appendonly yes"
    30. jump_mysql:
    31. container_name: jump_mysql
    32. image: harbor.corp.sdo.com/library/mysql:8.0
    33. environment:
    34. - "MYSQL_ROOT_PASSWORD=123456"
    35. - "MYSQL_DATABASE=jump"
    36. volumes:
    37. - "./my.cnf:/etc/mysql/my.cnf"
    38. ports:
    39. - "13306:3306"

    container_name:是容器的名字

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

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

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

    以下是my.cnf文档

    1. # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
    2. #
    3. # This program is free software; you can redistribute it and/or modify
    4. # it under the terms of the GNU General Public License as published by
    5. # the Free Software Foundation; version 2 of the License.
    6. #
    7. # This program is distributed in the hope that it will be useful,
    8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
    9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    10. # GNU General Public License for more details.
    11. #
    12. # You should have received a copy of the GNU General Public License
    13. # along with this program; if not, write to the Free Software
    14. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    15. #
    16. # The MySQL Server configuration file.
    17. #
    18. # For explanations see
    19. # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
    20. [mysqld]
    21. pid-file = /var/run/mysqld/mysqld.pid
    22. socket = /var/run/mysqld/mysqld.sock
    23. datadir = /var/lib/mysql
    24. secure-file-priv= NULL
    25. skip_ssl
    26. default_authentication_plugin = mysql_native_password
    27. # Disabling symbolic-links is recommended to prevent assorted security risks
    28. symbolic-links=0
    29. # Custom config should go here
    30. !includedir /etc/mysql/conf.d/

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

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

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

  • 相关阅读:
    Docker 镜像仓库是什么?有哪些镜像仓库命令?
    代码随想录算法训练营29期Day63|LeetCode 503,42
    使用 Docker 部署高可用 MongoDB 分片集群
    人工智能与设计的未来趋势,人工智能和建筑设计
    pm2 运行springboot项目
    Exception in thread “main“ java.io.NotSerializableException:
    FPGA实现直流电机驱动(速度位置控制)
    nRF52832的硬件资源小结
    学习pytorch13 神经网络-搭建小实战&Sequential的使用
    java集合list map set
  • 原文地址:https://blog.csdn.net/choudan8888/article/details/134034512