docker-compose 安装 redis/mysql/elk

安装docker

安装命令如下:
curl -fsSL https://get.docker.com | bash -s docker --mirror aliyun
也可以使用国内 daocloud 一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh

安装docker-compose

curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

编写docker-compose.yaml

version: '3'
services:
    mysql-dev:
        image: mysql:5.7
        container_name: mysql
        restart: always
        ports:
         - "3306:3306"
        volumes:
         - ./mysql:/var/lib/mysql
         - ./my.cnf:/etc/mysql/conf.d/my.cnf
        environment:
         # 默认数据库密码为password
         - MYSQL_ROOT_PASSWORD=password
    redis-dev:
        image: redis:5
        container_name: redis
        restart: always
        # 默认redis密码为password
        command: redis-server --requirepass "123456"
        ports:
         - "6379:6379"
    elasticsearch-dev:
        image: elasticsearch:7.12.1
        container_name: elk
        restart: always
        environment:
         - bootstrap.memory_lock=true
         - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
         - discovery.type=single-node
        ulimits:
            memlock:
                soft: -1
                hard: -1
        volumes:
         - ./es/data:/usr/share/elasticsearch/data
         - ./es/logs:/usr/share/elasticsearch/logs
         - ./es/plugins:/usr/share/elasticsearch/plugins
        ports:
         - "9200:9200"

执行命令和展示

docker-compose up -d
docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED       STATUS       PORTS                                                  NAMES
84c4541440d6   elasticsearch:7.12.1   "/bin/tini -- /usr/l…"   2 weeks ago   Up 2 hours   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 9300/tcp    elk
b47f698e3c7a   redis:5                "docker-entrypoint.s…"   2 weeks ago   Up 2 hours   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp              redis
33e383ccf60c   mysql:5.7              "docker-entrypoint.s…"   2 weeks ago   Up 2 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
: )