Docker Hub
-
Docker Hub is an image cloud repository run and managed by Docker Corporation
-
Docker Hub official address: hub.docker.com/
-
Through Dcoker Hub, you can search for included bulletin images and deploy the mirror warehouse privately
-
Docker Hub official website Image with Offical Image logo, for official release, more secure and reliable
MySQL
-
Open Docker Hub official website and search for MySQL Image. It is recommended to select the Image with Offical Image logo
-
You can view the Description document in Description and the version number in Tags
-
Pull the mirror
Docker pull mysql: 8.0.27Copy the code
-
MySQL container basic start command
docker run --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag Copy the code
Use -e to specify the environment variables and MYSQL_ROOT_PASSWORD to specify the password of user root
Use -p to specify the port mapping to map 3306 from the container to host 3306 for external access
-
MySQL container data persistence
docker run --name some-mysql -p 3306:3306 -v /my/custom/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag Copy the code
-v is used to specify volume mapping. MySQL container data is stored in /var/lib/mysql by default. The data volume is mapped to the host directory (which can be created automatically) for easy backup
The MySQL container is persisted to the host directory, and when it is mounted again, the original database table data and database password Settings are automatically loaded
-
MySQL container custom configuration file
/etc/ mysql.my.cnf; /etc/ mysql.my.cnf; Includedir includes /etc/mysql.conf. d and /etc/mysql.conf. d. Mysql.conf. d stores default configuration files. Generally, you only need to map mysql. CNF to /etc/mysql.conf. d
docker run --name some-mysql -p 3306:3306 -v /my/custom/data:/var/lib/mysql -v /my/custom/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag Copy the code
-
MySQL container common startup environment variables
MYSQL_DATABASE specifies the name of the database created at startup
MYSQL_USER, MYSQL_PASSWORD Specifies the user and password for MYSQL_DATABASE
MySQL database can be initialized by mapping SQL scripts or Shell script files under /docker-entrypoint-initdb.d
nginx
-
Pull the Nginx image
Docker pull nginx: 1.21.3Copy the code
-
Run the Nginx Web service
Docker run - name some - nginx - v/some/the content: / usr/share/nginx/HTML: ro # : ro for read-only, container data change does not affect the external - d nginx: tagCopy the code
When used as a Web server, nginx container Web resources are stored in /usr/share/nginx/ HTML by default and mapped to the host directory for deploying front-end systems
-
Configure the nginx reverse proxy
The nginx container configuration file is stored in /etc/nginx/nginx.conf by default
If the configuration file template is not available, start a temporary container and copy it to the host using the docker cp command
docker run --name tmp-nginx -d nginx docker cp tmp-nginx:/etc/nginx/nginx.conf /host/path/nginx.conf docker rm -f tmp-nginx Copy the code
Modify nginx.conf and add the reverse proxy configuration as follows
Upstream myServers {server 192.168.1.8; Server 192.168.1.9; Server 192.168.1.10. } server { location / { proxy_pass: http://myservers/;}}Copy the code
Start the nginx container
docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf -d nginx:tag Copy the code
Redis
-
Pull the Redis image
Docker pull redis: 6.2.5Copy the code
There are different versions of the same version number, such as 6.2.5-Buster, [6.2.5-alpine], the difference is based on the Linux system, the size and built-in tools are different
-
Start the Redis
docker run --name some-redis -p 6379:6379 -d redis:tag Copy the code
-
Enable data persistence
Snapshot mode (enabled by default). The snapshot file is the dump. RDB file in the /data directory of the container
docker run --name some-redis -p 6379:6379 -v /var/docker/redis/data:/data -d redis:tag Copy the code
Enable AOF persistence to reduce the risk of data loss, which can occur within a maximum of one second
docker run --name some-redis -p 6379:6379 -v /var/docker/redis/data:/data -d redis:tag redis-server --appendonly yes # You can append the commands to be executed by the container after startup directly after the run commandCopy the code
The AOF file is called appendone.aof and is generated to /data by default
-
Custom Redis profile
Create the redis.conf configuration file and add custom configuration items
#To enable remote access, set this parameter to 0.0.0.0The bind 0.0.0.0#Open AOF appendonly yes #Set port port 6379 #Setting an Access Password requirepass xxxxx Copy the code
Start Redis and load the custom redis.conf
docker run --name some-redis -p 6379:6379 -v /var/docker/redis/data:/data -v / var/docker/redis/redis. Conf: / etc/redis. Conf # mount configuration file - d redis: tag redis server/etc/redis. Conf # starts the server using the configuration fileCopy the code