docker
docker-compose 启动 mysql、mongodb
- docker-compose.yaml
- 运行docker-compose
- 本机进行链接(django示例
- mysql
- mpongodb
- 停止容器(mysq And mongo)
docker-compose.yaml
version: "3"
services:mysql:image: mysql:5.7container_name: mysql_testenvironment:MYSQL_ROOT_PASSWORD: 123456MYSQL_USER: testMYSQL_PASSWORD: 123456ports:- 3306:3306volumes:- mysqlvolume:/var/lib/mysqlnetworks:extnetwork:ipv4_address: 172.30.0.2command: docker-entrypoint.sh mysqldprivileged: truerestart: alwaysmongo:image: mongo:3.2.21container_name: mongo_testhostname: mongoenvironment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: testports:- 27056:27017- networks:extnetwork:ipv4_address: 172.30.0.3volumes:- /data/DRBRAIN_online_test/DrBrain3/Docker/docker-compose/local/mongo/db:/data/db # 此处为了让数据持久化privileged: truerestart: alwaysvolumes:mysqlvolume:external: truenetworks: extnetwork: ipam: config: - subnet: 172.30.0.0/16
运行docker-compose
docker-compose up -d
本机进行链接(django示例
mysql
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','HOST': '172.17.0.1', # 数据库主机'PORT': 3306, # 数据库端口'USER': 'root', # 数据库用户名'PASSWORD': '123456', # 数据库用户密码'NAME': 'test', # 数据库名字}
}
mpongodb
import mongoengineINSTALLED_APPS = [···'mongoengine',
]# mongodb相关配置
MONGO_USER='root'
MONGO_PWD='test'
MONGO_IP='172.0.0.1'
MONGO_PORT=27056MONGO_CONN = mongoengine.connect(db='test',#需要进行操作的数据库名称alias='default',#必须定义一个default数据库host=MONGO_IP,port=MONGO_PORT,username=MONGO_USER,password=MONGO_PWD,authentication_source="admin",#进行身份认证的数据库
)
停止容器(mysq And mongo)
docker-compose down
docker
docker-compose 启动 mysql、mongodb
- docker-compose.yaml
- 运行docker-compose
- 本机进行链接(django示例
- mysql
- mpongodb
- 停止容器(mysq And mongo)
docker-compose.yaml
version: "3"
services:mysql:image: mysql:5.7container_name: mysql_testenvironment:MYSQL_ROOT_PASSWORD: 123456MYSQL_USER: testMYSQL_PASSWORD: 123456ports:- 3306:3306volumes:- mysqlvolume:/var/lib/mysqlnetworks:extnetwork:ipv4_address: 172.30.0.2command: docker-entrypoint.sh mysqldprivileged: truerestart: alwaysmongo:image: mongo:3.2.21container_name: mongo_testhostname: mongoenvironment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: testports:- 27056:27017- networks:extnetwork:ipv4_address: 172.30.0.3volumes:- /data/DRBRAIN_online_test/DrBrain3/Docker/docker-compose/local/mongo/db:/data/db # 此处为了让数据持久化privileged: truerestart: alwaysvolumes:mysqlvolume:external: truenetworks: extnetwork: ipam: config: - subnet: 172.30.0.0/16
运行docker-compose
docker-compose up -d
本机进行链接(django示例
mysql
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','HOST': '172.17.0.1', # 数据库主机'PORT': 3306, # 数据库端口'USER': 'root', # 数据库用户名'PASSWORD': '123456', # 数据库用户密码'NAME': 'test', # 数据库名字}
}
mpongodb
import mongoengineINSTALLED_APPS = [···'mongoengine',
]# mongodb相关配置
MONGO_USER='root'
MONGO_PWD='test'
MONGO_IP='172.0.0.1'
MONGO_PORT=27056MONGO_CONN = mongoengine.connect(db='test',#需要进行操作的数据库名称alias='default',#必须定义一个default数据库host=MONGO_IP,port=MONGO_PORT,username=MONGO_USER,password=MONGO_PWD,authentication_source="admin",#进行身份认证的数据库
)
停止容器(mysq And mongo)
docker-compose down