DNMP (Docker + Nginx/Openresty + MySQL5,8 + PHP7,8 + Redis + ElasticSearch + MongoDB + RabbitMQ) is a full-featured modelLNMP one-click installer with Support for Arm CPUs。
It is best to read it in advance before usedirectory, in order to get started quickly, and problems can be eliminated in time.
[中文] - [GitHub Address] -
DNMP Project Features:
100%open source100%Follow docker standards- Supports the coexistence of multiple versions of PHP, can be switched arbitrarily (PHP7.0, PHP7.1, PHP7.2, PHP7.3, PHP7.4, PHP8.0)
- Supports binding Any number of domain names
- Supports HTTPS and HTTP/2
- PHP source code, MySQL data, configuration files, log filesAll can be directly modified in Host
- Built-in Full PHP extension installation command
- Supports
pdo_mysql、mysqli、mbstring、gd、curl、opcacheby default and other commonly used and popular extensions, flexibly configured according to the environment - One-click selection of common services:
- Multiple PHP versions: PHP7.0-7.4, PHP8.0
- Web services: Nginx, Openresty
- Databases: MySQL8, Redis, MongoDB, ElasticSearch
- Message Queuing: RabbitMQ
- Accessibility: Kibana, Logstash, phpMyAdmin, phpRedisAdmin, AdminMongo
- Apply in real projects, ensure
100%available - All mirrors originate from Docker official repository, safe and reliable
- One configuration, Windows、Linux、MacOs all available
- Supports quick installation extension commands
install-php-extensions apcu - Supports installing CERTBOT to obtain SSL certificates for free https
- 1. Directory structure
- 2. Quick to use
- 3.PHP and extensions
- 4. Administrative commands
- 5. Use Log
- 6. Database management
- 7. Safe to use in a formal environment
- 8. Frequently Asked Questions
/
├── data data directory
│ ├── esdata ElasticSearch data
│ ├── mongo MongoDB data
│ ├── mysql MySQL8 data
├── services Service build file and configuration file directory
│ ├── elasticsearch ElasticSearch configuration
│ ├── mysql MySQL8 configuration
│ ├── nginx Nginx configuration
│ ├── php PHP7.4 configuration
│ ├── php80 PHP8.0 configuration
│ └── redis Redis configuration
├── logs Log directory
├── docker-compose.sample.yml Docker compose configuration sample file
├── env.smaple Environment configuration sample file
└── www PHP codebase
- Local installation
gitDocker(The system needs to be Linux, Windows 10 Build 15063+, or MacOS 10.12+, and must be.)64bit)docker-compose 1.7.0+
cloneProject:$ git clone https://github.com/weimjay/dnmp.git- If the host is a Linux system and the current user is not
rootUsers, you also need to join the current userdockerUser Groups: $ sudo gpasswd -a ${USER} docker - Copy and name the configuration file (for Windows systems.)
copycommand), start:$ cd dnmp # Enter the project directory $ cp env.sample .env # Copy the environment variable file $ cp docker-compose.sample.yml docker-compose.yml # Copy the docker-compose configuration file. 3 services are started by default: # Nginx、PHP7和MySQL8. To enable more other services, such as redis, such as Redis, # PHP8.0, MongoDB, ElasticSearch,Please remove the comment before the service block $ docker-compose up # start up - Access in a browser:
http://localhostorhttps://localhost(Self-signed HTTPS demo) can see the effect of PHP code in the file./www/localhost/index.php。
First, you need to start another version of PHP, such as PHP 5.4, so that's the first stepdocker-compose.ymlDelete the comments that preceded PHP5.4 from the file and start the PHP5.4 container.
After PHP5.4 starts, open Nginx Configuration and modify itfastcgi_passThe host address of the company, by phptophp54As follows:
fastcgi_pass php:9000;
For:
fastcgi_pass php54:9000;
thereinto php and php54 bedocker-compose.ymlThe name of the server in the file.
At lastReboot Nginx Take effect.
$ docker exec -it nginx nginx -s reloadHere are twonginx, the first is the container name, and the second is in the containernginxProcedure.
Many of php's features are implemented through extensions, and installing extensions is a slightly time-consuming process.
So, in addition to the PHP built-in extension, inenv.sampleIn the file we only install a small number of extensions by default,
If you want to install more extensions, open yours.envModify the following PHP configuration,
Add the required PHP extensions:
PHP_EXTENSIONS=pdo_mysql,opcache,redis # PHP 要安装的扩展列表,英文逗号隔开
PHP54_EXTENSIONS=opcache,redis # PHP 5.4要安装的扩展列表,英文逗号隔开Then re-build the PHP image.
docker-compose build phpSee the available extensions in the same fileenv.sampleComment block description.
1. Enter the container:
docker exec -it php /bin/sh
install-php-extensions apcu 2. Support quick installation extension list
| Extension | PHP 5.5 | PHP 5.6 | PHP 7.0 | PHP 7.1 | PHP 7.2 | PHP 7.3 | PHP 7.4 | PHP 8.0 | PHP 8.1 |
|---|---|---|---|---|---|---|---|---|---|
| amqp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| apcu | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| apcu_bc | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
| ast | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| bcmath | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| blackfire | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| bz2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| calendar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| cmark | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
| csv | ✓ | ✓ | ✓ | ✓ | |||||
| dba | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| decimal | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| ds | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| enchant | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ev | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| event | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| excimer | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
| exif | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ffi | ✓ | ✓ | ✓ | ||||||
| gd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gearman | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| geoip | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| geospatial | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gettext | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gmagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| gnupg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| grpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| http | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| igbinary | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| imagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| imap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| inotify | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| interbase | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
| intl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ioncube_loader | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| jsmin | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| json_post | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ldap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| lzf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mailparse | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| maxminddb | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
| mcrypt | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| memcache | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| memcached | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mongo | ✓ | ✓ | |||||||
| mongodb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mosquitto | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| msgpack | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| mssql | ✓ | ✓ | |||||||
| mysql | ✓ | ✓ | |||||||
| mysqli | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| oauth | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| oci8 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| odbc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| opcache | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| opencensus | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| openswoole | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
| parallel* | ✓ | ✓ | ✓ | ✓ | |||||
| pcntl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pcov | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| pdo_dblib | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| pdo_firebird | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_mysql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_oci | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| pdo_odbc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_pgsql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pdo_sqlsrv* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| pgsql | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| propro | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| protobuf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| pspell | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| pthreads* | ✓ | ✓ | ✓ | ||||||
| raphf | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| rdkafka | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| recode | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
| redis | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| seaslog | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| shmop | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| smbclient | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| snmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| snuffleupagus | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| soap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sockets | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| solr | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sourceguardian | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| spx | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
| sqlsrv* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| ssh2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| stomp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| swoole | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sybase_ct | ✓ | ✓ | |||||||
| sysvmsg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sysvsem | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| sysvshm | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| tensor* | ✓ | ✓ | ✓ | ✓ | |||||
| tidy | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| timezonedb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| uopz | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| uploadprogress | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| uuid | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| vips* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| wddx | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
| xdebug | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| xhprof | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| xlswriter | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| xmldiff | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| xmlrpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| xsl | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| yac | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| yaml | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| yar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| zephir_parser | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
| zip | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| zookeeper | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| zstd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Number of supported extensions: 116
This extension comes fromhttps://github.com/mlocati/docker-php-extension-installer Refer to the sample files
- referencebash.alias.sampleSample file, copy the corresponding php cli function to the host
~/.bashrcFile. - To make a file work:
source ~/.bashrc
- You can then execute php commands in the host:
~ php -v PHP 7.2.13 (cli) (built: Dec 21 2018 02:22:47) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.13, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
Method 1: Use the compare command in the host
- Determine the path to the compiler cache. For example, my dnmp download is in
~/dnmpdirectory, that compiler's cache path is~/dnmp/data/composer。 - Refer to bash.alias.sample, a sample file that copies the corresponding php composer function to the host
~/.bashrcFile.It is important to note here that the sample file is in
~/dnmp/data/composerThe directory needs to be the directory identified in the first step. - To make a file work:
source ~/.bashrc
- You can use a composer in any directory on the host:
cd ~/dnmp/www/ composer create-project yeszao/fastphp project --no-dev
- Optionally, the first time you use composer, it will be
~/dnmp/data/composerGenerate one under the directoryconfig.jsonfile, in which you can specify a domestic repository, for example:{ "config": {}, "repositories": { "packagist": { "type": "composer", "url": "https://mirrors.aliyun.com/composer/" } } }
Method 2: Use the composer command inside the container
There is another way, which is to go into the container and executecomposer command, using the PHP7 container as an example:
docker exec -it php /bin/sh
cd /www/localhost
composer updateTo manage services, follow the command with the server name, for example:
$ docker-compose up # Create and start all containers
$ docker-compose up -d # Create and start all containers in background mode
$ docker-compose up nginx php mysql # Create and start multiple containers of nginx, php, and mysql
$ docker-compose up -d nginx php mysql # Create and start nginx, php, and mysql containers running in the background
$ docker-compose start php # Start service
$ docker-compose stop php # Stop service
$ docker-compose restart php # Restart service
$ docker-compose build php # Build or rebuild the service
$ docker-compose rm php # Delete and stop the php container
$ docker-compose down # Stop and delete containers, networks, images and mounted volumesAt the time of development, we may use it oftendocker exec -itEntering the container and aliasing the commands commonly used is a convenient way to do so.
First, review the available containers in the host:
$ docker ps # show all running containers
$ docker ps -a # show all containersOutputNAMESThat column is the name of the container, or if the default configuration is used, then the name isnginx、php、php56、mysqlWait.
Then, open~/.bashrcor~/.zshrcfile, plus:
alias dnginx='docker exec -it nginx /bin/sh'
alias dphp='docker exec -it php /bin/sh'
alias dphp56='docker exec -it php56 /bin/sh'
alias dphp54='docker exec -it php54 /bin/sh'
alias dmysql='docker exec -it mysql /bin/bash'
alias dredis='docker exec -it redis /bin/sh'The next time you enter the container, it is very fast, such as entering the php container:
$ dphpifconfig docker0For filling inextra_hostsThe container accesses the hosthostsaddress
The location where the log file is generated depends on the value of each log configuration under conf.
Nginx logs are the logs we use the most, so we put them separately in the root directorylogUnder.
logThe directory will be mapped for the Nginx container/var/log/nginxdirectory, so in the Nginx configuration file, the location of the output log needs to be configured/var/log/nginx, such as:
error_log /var/log/nginx/nginx.localhost.error.log warn;
In most cases, PHP-FPM logs are output to Nginx's logs, so no additional configuration is required.
In addition, it is recommended to open the error log directly in PHP:
error_reporting(E_ALL);
ini_set('error_reporting', 'on');
ini_set('display_errors', 'on');If you really need it, you can open it (in a container) by following the steps below.
- Go to the container, create a log file, and modify the permissions:
$ docker exec -it php /bin/sh $ mkdir /var/log/php $ cd /var/log/php $ touch php-fpm.error.log $ chmod a+w php-fpm.error.log
- Open and modify the configuration file for PHP-FPM on the host
conf/php-fpm.conf, find the following line, delete the comment, and change the value to: php_admin_value[error_log] = /var/log/php/php-fpm.error.log - Restart the PHP-FPM container.
Because MySQL in the MySQL container is usedmysqlThe user starts, it cannot be self-contained/var/logAdd log files under Add log files. So, we put mySQL logs in the same directory as data, i.e. projectsmysqldirectory, corresponding to the container/var/log/mysql/Directory.
slow-query-log-file = /var/log/mysql/mysql.slow.log
log-error = /var/log/mysql/mysql.error.logThe above is the configuration of the log file in mysql.conf.
This project defaults to docker-compose.yml For MySQL online management is not turned on phpMyAdmin, and for redis online management phpRedisAdmin, which can be modified or deleted as needed.
The port address of the phpMyAdmin container mapped to the host is:8080, so the address on the host to access phpMyAdmin is:
http://localhost:8080
MySQL connection information:
- host: (MySQL container network for this project)
- port:
3306 - username:(Manually entered in the phpmyadmin interface)
- password:(Manually entered in the phpmyadmin interface)
The port address of the phpRedisAdmin container mapped to the host is:8081, so the address on the host to access phpMyAdmin is:
http://localhost:8081
The Redis connection information is as follows:
- host: (Redis Container Network for this project)
- port:
6379
To use in a formal environment, please:
- Turn off XDebug debugging in php .ini
- Security policies to enhance Access to MySQL databases
- Enhanced security policies for redis access
Refer to this issue:garylab/dnmp#91
Docker uses cron to time tasks
The container time is configured in an .env fileTZFor variables, see all supported time zonesList of time zones on WikipediaorList of time zones supported by PHP· PHP official website。
There are two cases of this.
The first case, inPHP code。
// Connect to MySQL
$dbh = new PDO('mysql:host=mysql;dbname=mysql', 'root', '123456');
// Connect to Redis
$redis = new Redis();
$redis->connect('redis', 6379);Because containers are containersexposeThe ports are connected, and they are in the same onenetworksdown, so connectedhostParameters directly with the container name,portThe parameter is the port inside the container. Please refer to it for moreThe Difference Between Docker-compose Ports and Expo。
In the second case,In the hostPasscommand lineorNavicatand other tools connected. For the host to connect mysql and redis, the container must pass throughportsThe port is mapped to the host. Take mysql as an example.docker-compose.ymlThere is such a thing in the documentportsDisposition:3306:3306, that is, the 3306 port of the host and the 3306 port of the container form a map, so we can connect like this:
$ mysql -h127.0.0.1 -uroot -p123456 -P3306
$ redis-cli -h127.0.0.1Over herehostThe parameter cannot be used localhost because it communicates with mysql through the sock file by default, and the container is isolated from the host file system, so it needs to be connected via TCP, so you need to specify the IP.
- Host execution
ifconfig docker0getinetIt's about connectingipaddress
$ ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
...- Run the host Mysql command line
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql>flush privileges;
// The meaning of each character:
// *.* Valid for any table in any database
// "root" "123456" are the database username and password
// '%' means allowing any IP address to access the database, you can also specify the IP address
// flush privileges Refresh permission information- Then use the php container directly
172.0.17.1:3306Just connect
This project currently uses mysql-server 8.0.28 or above, and the php version requires 7.4.7 or above to connect.
MIT