Docker 构建etcd集群、redis、mysql

1.docker pull quay.io/coreos/etcd //下拉镜像

2.touch docker-compose.yaml
3.vi docker-compose.yaml

4.//复制以下内容到yaml
version: '2'
networks:
  byfn:
services:
  etcd1:
    image: quay.io/coreos/etcd
    container_name: etcd1
    command: etcd -name etcd1 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state new
    ports:
      - "12379:2379"
      - 2380
    networks:
      - byfn
  etcd2:
    image: quay.io/coreos/etcd
    container_name: etcd2
    command: etcd -name etcd2 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state new
    ports:
      - "22379:2379"
      - 2380
    networks:
      - byfn
  etcd3:
    image: quay.io/coreos/etcd
    container_name: etcd3
    command: etcd -name etcd3 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state new
    ports:
      - "32379:2379"
      - 2380
    networks:
      - byfn

5.docker-compose up



etcd集群构建

2.redis构建

1.docker pull redis:latest //拉镜像

2.docker run -itd --name redis-test -p 6379:6379 redis //构建容器

3.docker exec -it redis-test /bin/bash //进去容器

4.redis-cli //进入redis中

3.构建mysql

1.docker pull mysql:latest //拉镜像

2.docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
 //构建容器

3.docker exec -it mysql-test /bin/bash //进去容器

4.mysql -h localhost -u root -p // 回车进入mysql中 password 123456

 

你可能感兴趣的:(KVDB,golang)