Docker Hub

  1. Docker Hub is an image cloud repository run and managed by Docker Corporation

  2. Docker Hub official address: hub.docker.com/

  3. Through Dcoker Hub, you can search for included bulletin images and deploy the mirror warehouse privately

  4. Docker Hub official website Image with Offical Image logo, for official release, more secure and reliable

MySQL

  1. Open Docker Hub official website and search for MySQL Image. It is recommended to select the Image with Offical Image logo

  2. You can view the Description document in Description and the version number in Tags

  3. Pull the mirror

    Docker pull mysql: 8.0.27Copy the code

  4. 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

  5. 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

  6. 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

  7. 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

  1. Pull the Nginx image

    Docker pull nginx: 1.21.3Copy the code
  2. 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

  3. 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

  1. 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

  2. Start the Redis

    docker run --name some-redis -p 6379:6379 -d redis:tag
    Copy the code
  3. 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

  4. 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