Comments on Dockerizing LEMP Stack with Docker-Compose on Ubuntu
In this tutorial, I will guide you step-by-step to use docker-compose to create a LEMP Stack environment (LEMP = Linux - Nginx - MySQL - PHP). We will run all components in different docker containers, we set up a Nginx container, PHP container, PHPMyAdmin container, and a MySQL/MariaDB container.
23 Comment(s)
Comments
Nice try but bad execution. Sorry.
The phpmyadmin Docker image already includes phpfpm and nginx. So you have 2 phpfpm and 2 nginx services for no reason. Also running random Docker images is never a good idea. Why not using official images?
@Jetchko I disagree with your assessment of bad execution. This is the idea of Docker. Just as an exercise, what if PHPMyAdmin required a different version of PHP than an app that was running in another container? What if for some reason Apache was needed? The power of Docker is in creating simple useful containers, not building smaller virtual machines.
In fact, this setup is the most secure/flexible. The PHPMyAdmin container can be started and stopped when needed.
Although I do agree with not running random images, but you can go through the entire stack and determine if it is what you need.
Agreed, it could be better - bitnami runs Apache while this stack runs NGINX too BUT the tutorial was about quick.
Ideally the solution would have 1 web server/proxy to reduce overhead and the proxy would handle pgpMyAdmin too.
Are the hypens needed in the docker-compose.yml for the environment definitions for the phpmyadmin service?
Slightly related - container security/deployment/management best practice presentations from SouthEast LinuxFest 2016: https://www.youtube.com/playlist?list=PLvG1nXgsl22FhL55suZtb7RIjEJtkYYC5 Learned a bunch here last year. Mainly don't deploy container images from untrusted sources. Seems obvious, right? What do each container repo require to post an image?
Great how-to, I wull give it a try as soon as I find some time.
@Jetchko
It would be nice if you gave some more information and/or (less generic) suggestions
1. phpmyadmin Docker image already includes phpfpm and nginx, maybe the official one, the bitnami/php-fpm does not seem to contain them...
2. Also running random Docker images is never a good idea, not true the bitnami images are not just "random images", last instead of downloading the image you can always build them yourself.
how do I get the server IP Address ?
If you are not looking for the IP given the container. Your servers IP should be the same as the Host you are running docker on.
Thanks for publishing instruction to setup a LEMP stack in docker. I ran into a bit of any issue, but maybe it was expected with this setup.
The first PHP dependent application I tested post install of LEMP stack was GRAV. However GRAV was not working properly as pages where not loading. When I checked the Nginx logs I saw an error "FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream. I made changes to the php location variable in app.conf, as this was a common answer with the error, but changing the php location information did not fix my issue.
The issue is related to the document root set in the app.conf file. Folder containing GRAV is nested one folder under myapps folder. Once I changed the root variable to something like /myapps/GRAVFOLDER, everything worked as expected.
I wanted to inquire if it is possible to have subfolders with PHP application within, served correctly with this setup. I would prefer not to have to specify document root if testing multiple PHP applications.
Thanks for publishing instruction to setup a LEMP stack in docker.
In addition to the compose command line readers might find useful our GUI for Docker on Ubuntu.
It is named Data Pulley. http://datapulley.com
Data Pulley is a lightweight management UI which allows you to easily manage Docker containers on your local machine.
And, we have just added option to run using Docker Compose as well (File -> Open Docker Compose)
after issuing up command:
nginx_1 | nami INFO Initializing nginx
nginx_1 | nginx INFO ==> nginx.conf not found. Applying bitnami configuration...
nginx_1 | nami INFO nginx successfully initialized
nginx_1 | INFO ==> Starting nginx...
but inside the container:
I have no name!@2f154646a240:/opt/bitnami/nginx/html$ nginx -t
nginx: the configuration file /opt/bitnami/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/bitnami/nginx/conf/nginx.conf test is successful
What is the issue?
I'm going to assume that you are maybe running into the same problem that I was getting. Going to 127.0.01:80 in my browser was giving me a message saying "the connection was reset."
I logged onto the nginx box to see what was going on by using ...
docker exec -it --user root lempcompose_nginx_1 bash
... and then looked at the contents of the config file via ...
cat /opt/bitnami/nginx/conf/nginx.conf
... and found that by default, nginx is serving on port 8080 rather than port 80, which is what this tutorial was mapping. So in my docker-compose.yml file, (under nginx:ports:) I added this line:
- '21212:8080'
... and then I was able to go to http://127.0.0.1:21212/ and get a nice message welcoming me to nginx.
I'll still end up having to do a bit more reconfiguration for my needs, but after wasting half a weekend, I am happy that I finally got this thing "working" to some extent, and I hope that my experience can at least set somebody on the right track. Cheers!
when i do compose up -d and see the logsi got this :
nginx_1 | INFO ==> Starting nginx...
nginx_1 | 2017/12/10 20:00:19 [emerg] 19#0: open() "/opt/bitnami/nginx/logs/myapp-error.log" failed (13: Permission denied)
nginx_1 | nginx: [emerg] open() "/opt/bitnami/nginx/logs/myapp-error.log" failed (13: Permission denied)
lempcompose_nginx_1 exited with code 1
any idea guys?
I got similar error as nitima, Can you please share how was this resolved?
chmod 777 logs/error.log logs/access.log
It would solve your issue.
Nice tutorial, but needs some update in the nginx blocks of docker-compose file.
The volumes should be:
- ./nginx/app.conf:/bitnami/nginx/conf/vhosts/myapp.conf
- ./public:/app
and not
- ./nginx/app.conf:/bitnami/nginx/conf/vhosts/app.conf
- ./public:/myappss
nice tutorial, can you explain @Joshua why we should add IP server_name 193.70.36.50;
in nginx config?
I have this same question. Any help would be appreciated.
It's a space-delimited list of addresses to allow NGINX to resolve to:
server_name 192.168.0.101 127.0.0.1 localhost legion-1 legion-1.kilbourne.local;Hey Guys,
Sorry for the stupid question but is the upstream server the webserver?
Thanks,
Michael
Hey Guys,
Sorry another stupid question, How would I configure it to host multiple websites? The same as the regular nginx would be configured? Any help would be greatly appreciated. If you have a sight or tutorial send me there i don't mind reading so I can get a thorough understanding.
Thank you again,
Michael
I had no problems except for an error message when I ran the test on the yml file. So downloaded the one from Github. It worked. I am not able to see info.php nor is the (purposely different) index.html showing up. Have looked for a document root, but alas none to be found. I also loaded a WordPress docker file, and it seems to have run as it shows up in the TREE display.
I'm totally new to Docker, so go easy on me. I follow directions flawlessly and yet NO JOY !
why expose port that are only used in the docker network and don't need to be open on the host?