In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to build a docker-based nodejs, php development environment". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to build a docker-based nodejs, php development environment".
Recently wrote a new project to deploy the nodejs,php development environment (docker,nodejs,php,nginx,mongo,mysql,redis) with one click
Because I recently started writing nodejs,php projects at the same time, and have to deploy to testing, pre-release, and online environments, other colleagues need the same environment. Building a complete set of development environment under different platforms is very tedious, so there is this project.
Github address: https://github.com/wallace5303/dnnmmp
If you have any questions or use exceptions, please help to point them out. Thank you!
Details are as follows:
The docker-based nodejs and php development environment Dnnmmp contains the following combinations
Dnm (Docker + Nodejs + Mysql/MongoDB/Redis)
Dnmn (Docker + Nodejs + Mysql/MongoDB/Redis + Nginx)
Dnmp (Docker + Nginx + Mysql/MongoDB/Redis + PHP)
Support system version: Linux, MacOs, Windows
Characteristics
1. Mainly for nodejs developers, php developers, operation and maintenance, front-end
two。 Support for multiple versions of php,nodejs
3. Compatible with OneinStack configuration files, perfect configuration instructions
4. Multiple domain names can be bound.
5. Clear docker file, configuration file, log file structure
6. Support for php extension installation
7. The program is based on the latest stable version of docker and downloaded from the official warehouse
8. Continuous updates to support interactive, unattended installation
Optional software version
Docker official warehouse
Nginx=1.17 / 1.16
Mysql=8 / 5.7 / 5.6
Nodejs=12 / 10 / 8
Php=7.4 / 7.3 / 7.2 / 7.1 / 5.6
Mongodb=4 / 3
Redis=5 / 4
Catalogue
1. Installation steps
two。 Command line usin
3.php extension
4. Journal
Appendix 1:docker installation
Appendix 2: directory structure
Appendix 3: collected websites commonly used by programmers
Appendix 4: frequently asked questions
1. Installation steps
Install git, docker, and docker-compose locally (the latest version 1.23 is recommended). Appendix 1:docker installation
Clone Project:
# if it is not a `root` user, add the current user to the `docker` user group $sudo gpasswd-a ${USER} docker# to get the project $git clone https://github.com/wallace5303/dnnmmp.git
Build and start:
$cd dnnmmp# builds and runs (this command is recommended for the first installation to facilitate viewing the printed log) $docker-compose up# runs $docker-compose up-d in the background
Note: students who install Windows Security Guard, please exit it first, otherwise the Docker account creation process may be blocked during installation, resulting in file sharing failure at startup.
View the generated image: $docker image ls
View the launched container: $docker container ls
Appendix 4: frequently asked questions
Access in the browser: http://localhost, https://localhost
Common command
# Service list: redis | mysql | mongodb | nginx | php# lists the images contained in the Compose file $docker-compose images# creates all services and starts $docker-compose up$ docker-compose up-d # all backend startup # create a single service $docker-compose up redis$ docker-compose up redis-d # background startup # if the container has been created # start $docker-compose start redis# stop $docker-compose stop redis # restart $docker-compose restart redis#, rebuild $docker-compose build redis#, delete $docker-compose rm redis
For more docker commands, see:
Docker
Docker-compose
two。 Command line usin
The programs installed by docker are different from those installed directly on the host. If you need to use the command line, there are two ways
(1) method 1: enter the container created by docker to execute the command
(2) method 2 (recommended): add bash shortcut command, as follows:
Edit ~ / .bashrc (or ~ / .zshrc) and add at the end of the line
# if the software is already installed on the computer Please change the function name node () {tty= tty-s & & tty=--tty docker run\ $tty\-interactive\-- rm\-- volume $PWD:/var/www/html:rw\-- workdir / var/www/html\ dnnmmp_node node "$@"} npm () {tty= tty-s & & tty=--tty docker run\ $tty\-interactive\-rm\-volume $PWD:/var/www/html:rw\-workdir / var/www/html\ dnnmmp_node npm "$@"} php () {tty= tty-s & & tty=--tty docker run\ $tty\-interactive\-rm\-volume $PWD:/var / www/html:rw\-workdir / var/www/html\ dnnmmp_php72 php "$@"} composer () {tty= tty-s & & tty=--tty docker run\ $tty\-interactive\-- rm\-- user $(id-g)\-- volume ~ / dnnmmp/composer:/tmp\ -- volume / etc/passwd:/etc/passwd:ro\-volume / etc/group:/etc/group:ro\-volume $(pwd): / app\ composer "$@"}
(3) give effect to the revised content
$source ~ / .bashrc (or ~ / .zshrc)
Note: if the prompt command does not exist, reopen the terminal window. (because the old terminal will not reload the file)
(4) View version information
$node-vv10.16.0$ npm-v6.9.0$ php-vPHP 7.2.19 (cli) (built: Jun 28 2019 03:58:08) (NTS) Copyright (c) 1997-2018 The PHP GroupZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.19, Copyright (c) 1999-2018, by Zend Technologies$ composer-vComposer version 1.8.6 2019-06-11 15:03:05
Quick access to the container
Students who know docker know that you often need to enter the container to view the contents and configure the command to enter the container.
Edit ~ / .bashrc (or ~ / .zshrc) and add:
Alias dmysql='docker exec-it dnnmmp_mysql_1 / bin/bash'alias dredis='docker exec-it dnnmmp_redis_1 / bin/sh'alias dnginx='docker exec-it dnnmmp_nginx_1 / bin/sh'alias dmongodb='docker exec-it dnnmmp_mongodb_1 / bin/sh'alias dphp72='docker exec-it dnnmmp_php72_1 / bin/bash'
To bring into effect:
$source ~ / .bashrc (or ~ / .zshrc)
3.php extension
Add extensions: Editing .env fil
# Select the appropriate extension from the list of extensions and add it to this line, with PHP72_EXTENSIONS=curl,opcache,redis separated by commas
Re-build PHP image: docker-compose build php72 docker-compose up-d
4. Journal
Php log directory:. / log/php/
Nginx log directory:. / log/nginx/
Mysql data and log directory:. / mysql/
Mongo data and log directory:. / mongo/
Appendix 1:docker installation
Docker installation
Docker-compose installation
Appendix 2: directory structure / ├── composer Composer configuration and caching ├── config configuration file │ ├── mongodb mongodb │ ├── Dockerfile Dockerfile file │ ├── mysql mysql │ ├── Dockerfile │ ├── mysql.cnf mysql configuration file │ ├── nginx nginx │ ├── conf.d │ ├── certs secret key │ ├── localhost_https.conf https virtual host │ ├── localhost.conf Virtual host │ ├── Dockerfile │ ├── nginx.conf nginx configure │ ├── node node │ ├── Dockerfile │ ├── php php ├── extensions extension and script │ ├── install.sh basic installation script │ ├── php56.sh php5.6 extension installation script │ ├── php72.sh php7.2 extension installation script │ ├── Dockerfile │ ├── php-fpm.conf php-fpm configuration file │ ├─ ─ php.ini php.ini configuration file │ ├── redis redis │ ├── Dockerfile │ ├── redis.conf redis configuration file ├── mongo mongodb data directory ├── log day Directory ├── mysql MySQL data directory ├── docker-compose.yml Docker service configuration ├── .env environment configuration └── www code directory thank you for reading The above is the content of "how to build a docker-based nodejs, php development environment". After the study of this article, I believe you have a deeper understanding of how to build a docker-based nodejs and php development environment, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.