本文主要是介绍使用Docker Compose部署包含MySQL、Redis、Nginx和Mosquitto的容器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一.离线安装Docker Compose
1.下载安装包Docker Compose
https://github.com/docker/compose/releases/download
https://objects.githubusercontent.com/github-production-release-asset-2e65be/15045751/93aa98bb-8fce-4c53-bc53-7ce2ecb1a872?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240528%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240528T084437Z&X-Amz-Expires=300&X-Amz-Signature=4617d4aff81fbb29acefe0f22091ef8122ea7f4c0d818c8345cd78c33e077914&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=15045751&response-content-disposition=attachment%3B%20filename%3Ddocker-compose-linux-aarch64&response-content-type=application%2Foctet-stream
2.上传到服务器
mv /bwss/upload/docker-compose-linux-aarch64 /usr/local/bin/
|
3.创建软链接以便于从任何位置调用 docker-compose
命令
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
4.测试安装情况
|
二.安装中间件
docker-compose.yml配置
version: '3'
services:mysql:image: mysql:5.7.30container_name: test-mysqlports:- "3307:3306"environment:MYSQL_ROOT_PASSWORD: 123456MYSQL_DATABASE: database_testMYSQL_USER: adminMYSQL_PASSWORD: admin123456restart: alwaysredis:image: redis:7.2.0container_name: test-redisports:- "6380:6379"restart: alwaysvolumes:- /bwss/docker_test/config/redis/conf/redis.conf:/etc/redis/redis.conf- /bwss/docker_test/config/redis/data:/datacommand: redis-server /etc/redis/redis.confnginx:image: nginx:1.25.5container_name: test-nginxports:- "8088:80" # 将主机的80端口映射到容器的80端口 restart: alwaysvolumes:- /bwss/docker_test/config/nginx/nginx.conf:/etc/nginx/nginx.conf # 如果需要自定义Nginx配置,可以挂载配置文件- /bwss/agent:/bwss/agent # 挂载你的网站文件到Nginx的默认web根目录mosquitto:image: eclipse-mosquitto:2.0.18container_name: test-mosquittoports:- "1884:1883"restart: alwaysvolumes:- /bwss/docker_test/config/mosquitto/conf:/mosquitto/config- /bwss/docker_test/config/mosquitto/data:/mosquitto/datamongodb:image: mongo:4.4container_name: test-mongodbports:- "27018:27017"restart: alwaysvolumes:- /bwss/docker_test/config/mongodb/db:/data/db- /bwss/docker_test/config/mongodb/conf:/data/configdb- /bwss/docker_test/config/mongodb/init/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js
执行以上脚本即可自动安装nginx,mysql,redis等中间件容器
执行脚本指令:docker-compose up -d
具体见附件包资源:https://download.csdn.net/download/x948130516/89396990
这篇关于使用Docker Compose部署包含MySQL、Redis、Nginx和Mosquitto的容器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!