Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
preface
For back-end developers, often need to use the database, in trouble and error-prone, local installation database using the docker can very quick LaQi database environment, need not when can delete, if you need to store data can be used to separate the data catalogue local hung on to the container, this paper enumerated several kind of commonly used simple database.
A MySQL
#Pull the mirrorDocker pull mysql: 8.0.19
#Start the serverDocker run --name mysql01 -p 13306:3306 -e MYSQL_ROOT_PASSWORD=mysqladmin -d mysql:8.0.19
#Start the client and enter the password: mysqladminDocker run it --network host --rm mysql mysql -h127.0.0.1 -p13306 --default-character-set= UTf8MB4 -uroot -pCopy the code
Two Redis
#Pull redis
docker pull redis
#Start the redis
docker run -itd --name redis01 -p 6379:6379 --requirepass "redisadmin" redis
#Use the client to link to Redis
docker exec -it redis01 /bin/bash
Copy the code
Three Etcd
#To the mirror
docker pull appcelerator/etcd:latest
#Start theDocker run --name etcd01-d-p 2379:2379-p 2380:2380 Appcelerator /etcd --listen-client-urls http://0.0.0.0:2379 - advertise - the client - urls http://0.0.0.0:2379
#Client link
docker exec -it etcd01 /bin/bash
Copy the code
Four Elasticsearch
#Pull the mirror
docker pull elasticsearch:latest
#Start the
docker run --name es01 -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" elasticsearch:latest
#Use the HEAD client link
docker pull mobz/elasticsearch-head:5
#Start the header container
docker run -d --name my-es_admin -p 9100:9100 mobz/elasticsearch-head:5
#Curl Test access
Copy the code
When you open the browser header for the first time, the connected service address is localhost:9200, and change it to the IP address where the docker resides. In this case, the connection fails. You need to modify the elasticSearch. yml file and add the elasticSearch. yml file
Allow-origin: "*" # restart es docker restart es01 docker restart my-es-headCopy the code
Five mongo
#Pull the mirror
docker pull mongo:lastest
#Start the
docker run --name mongodb01 -p 27017:27017 -d mongo:latest
#The client link enters the container as admin
docker exec -it mongodb01 mongo admin
Copy the code
Six postgre
#download
docker pull postgres:12
#Start the
docker run --name pg01 -e POSTGRES_PASSWORD=pgadmin -p 54320:5432 -d postgres:12
#Client link
docker exec -it pg01 /bin/bash
Copy the code
other
In this paper, by using Docker containerization encapsulation ability, the containing image is directly pulled down from the warehouse, run through the command line, and the specified port is mapped to the local. Then local development, do not need to pay attention to the configuration and installation of the database, in simple terms, is to query the mirror, pull the mirror, run the mirror. You can have a configured requirements database environment in three simple steps.