tl;dr
Want to take the fast track and skip the detailed tutorial below? Install Docker for your OS, clone this repo, add your Laravel ap...
For further actions, you may consider blocking this person and/or reporting abuse
Hi! I used your work as an inspiration for my Symfony 4 container, and it work perfectly. But php container (I think it's him) create a html folder inside of my /var/www folder, and I'm unable to understand why. Any clues?
Here is the link to my repo: github.com/guillotjulien/symfony4-...
Thanks :)
EDIT:
Just add
working_dir: /var/www
to php service :)Files generate in /src folder when execute artisan command inside php container is own by root,
example, running following command
will generate ExampleController.php on host machine and file is own by root.
Any idea how to avoid this?
I'm sorry if this is too late, but hopefully will help others, here's my workaround to solve the file owner issue, first you have to find-out whats your uid (normaly 1000):
id
. The result will be something like:uid:gid
in yourdocker-compose.yml
Also, you even don not need Dockerfile for php container!
If you run:
you can see that php modules already exists:
my bad,
pdo_mysql
do not exists on this image, unfortunately you should write Dockerfile if you want database access :)Hi! Thank you for great blog tutorials. It really helped me to get started. I have also watched you youtube video which took me here.
I am able to deploy container for laravel succesfully and now I want to install image GD library for PHP. I simply tried adding RUN docker-php-ext-install gd. But it didnot worked. Also, I want to upload large images 5 MB for which I need to make changes to NGINX config. I have tried modifying nginx.dockerfile but its now working. Can you please help me through it?
could you solve it?
Hi Andrew,
Appreciate your tutorial. It is very good and clear to understand. I have tried both of your tutorial form youtube. They are ok.
But I am trying to install all php extensions recommended by laravel. BCMath, Ctype, Fileinfo, JSON, Mbstring, OpenSSL, PDO, Tokenizer, XML. Some of them can be install easily. But some aren't. I have faced various errors. Would you mind showing how to install them.
Please add composer to php container.
Adding composer container will be better solution :)
I think I've got this set up, but it's slow on my Windows machine. When using WSL 2, Microsoft recommends you "store your files in the WSL file system", whatever that means, for performance reasons. I've played around with the volumes in docker-compose.yml, but I can't get it working. How would I do this? Thanks!
docs.microsoft.com/en-us/windows/w...
Hey Tim!
So essentially when it says "Store your files in the WSL file system" it means in the Linux partition that Windows creates when using WSL.
If you open up a Windows Terminal session in Bash, by default it should put you in a directory called like /mnt/c/Windows. Run
cd ~
to get to the home directory in the WSL file system, and then from there you can use any directory under that one to create your Docker-ized application and it will run way faster.For instance, I have mine at
~/Sites/example.com
. Let me know if that helps!So in your docker-compose.yml file, what do your volumes look like? I changed mine from
volumes:
- .src:/var/www/html
to
volumes:
- ~/site:/var/www/html
And now I get a 404 error, even thought there is an index.html file there.
To answer my own question, the answer is to run docker-compose inside wsl, not from the Windows prompt.
Dont know what i'm doing wrong but i typed in the files by hand and built the docker. On running the containers mysql and php run fine but nginx exits with the following log: Any ideas?
`
Hy Andrew, I have issues running this on windows please help
Creating mysql ... done
Creating php ... error
ERROR: for php Cannot create container for service php: b'Drive sharing failed for an unknown reason'
ERROR: for php Cannot create container for service php: b'Drive sharing failed for an unknown reason'
Encountered errors while bringing up the project.
You have to go on Settings and SHARE the driver you are trying to set up your project in it...
OK i cloned your repo installed a laravel app and ran the docker-compose command from the github repo. When I try to run a composer command using the container I run into this error
had to build all the containers
Thank you for your good tutorial.Can you help me in this issue? I tried everything but no use. I am running on window 10 but linux containers.
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations)
thepracticaldev.s3.amazonaws.com/i...
I don't know if you were able to solve this or not, but this is what worked for me:
In your .env file change this
for this
I guess it's because you need to specify the name of the container running the database server and in docker-compose.yml the name for the mysql service is
container_name: mysql
.Edit: I see now that the article clearly states that the value for DB_HOST needs to be
mysql
. For some reason my brain totally skipped that part...In your .env file for your Laravel application, what are your values for the database credentials?
Thanks for good
docker-compose.yml
example!But I'm curious about
SERVICE_TAGS: dev
andSERVICE_NAME: mysql
env variables for mysql container, for what they are?Did you ever figure this out? I've noticed it outside of this tutorial as well, and am also curious.
nice one, I like the nginx implementation so easy, but exactly how and when do I use "composer install"? I can't work without installing the packages!!
Hi Andrew,
Thanks for sharing this method. This is probably a concise guide on local development environment set up with Docker for running our Laravel applications. I also would like to suggest a post that will be helpful for readers on hiring Laravel developers: Read more.
Adding composer to Dockerfile to make it container specific.
Install Composer
RUN curl -sS getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
You should have composer in php container so that you can run composer commands via docker cli and install specific laravel version. Laravel 8 requires composer 2.
Hello friends, I follow all the tips step by step but I had the next problem, please can you help me:
$ docker-compose build
The Compose file '.\docker-compose.yml' is invalid because:
services.nginx.networks contains an invalid type, it should be an array, or an object
Hey David!
Check your spacing on that file. It should be indented appropriately, and possibly even have to use spaces instead of tabs. If you need to, you can compare it against the current docker-compose.yml file in the repository for that tutorial: github.com/aschmelyun/docker-compo...
I am new to docker and laravel but I like the clarity and simplicity of this project structure. Is there any chance you can show how to do this with apache server instead of nginx? (Laravel + Docker + Apache + MySQL) in this project structure?
Hi,
Thanks for your post and git repo. Great work.
I am facing a chalenge to run npm commands in npm container.
I started an project with Laravel and Vue, but i can't run npm commands to compile Vue components.
I installed npm on my machine, runned "npm run watch" and it works great, but how can i run this command using the npm container?
After docker-compose up -d, all containers are done well, but only three remain running "nginx, mysql and php", that is ok, but how can i run and exec comands in npm?
Sory my verbosity and of course my english.
Well, i start with my apologies.
I ran npm command using:
$ docker-compose run --rm npm run watch
But i will use this to ask if this (keep run watch open in terminal) is the best way to recompile Vue components?
Hi, Andrew!
From the positivity of the other comments, I understand that your guide works fine for others.
Yet I am getting this permission issue when I visit my localhost:
The stream or file "/var/www/storage/logs/laravel-2019-08-30.log" could not be opened: failed to open stream: Permission denied
thepracticaldev.s3.amazonaws.com/i...
I'm still learning and this got me confused.
Can you tell me what user:group and privileges to give to my project folder?
Hello Stoyan,
Have a look at Laravel permissions related to /storage directory (which contains logs) and /bootstrap/cache directory.
You will find plenty of documentation/stack overflows issues about it. :)
Edit :
laravel.com/docs/6.x/installation#...
Hi, it don't work for me
nginx | 2019/10/02 22:02:42 [emerg] 1#1: invalid log level "access_log" in /etc/nginx/conf.d/default.conf:6
nginx | nginx: [emerg] invalid log level "access_log" in /etc/nginx/conf.d/default.conf:6
Hi Andrew, nice articles.
But I have question, how about deploy to live server?
is it possible to add phpmyadmin..that way whenever you are running a container or a laravel project..you can use phpmyadmin to see data in database? if so, how to do it?
Thank you for your assistance.
Appreciate you
I just saw on your YouTube Channel that you did a video on it..thank you
Hi, Andrew! I have this error in browser
Beautiful article, btw!
Thank you, it helped me a lot. Please it will be great help if you could also add
1.Supervisord for scheduler and queue
2.gd extension and others
3.File permissions for storage and modify the docker compose with current one, as it is giving warning
Thank you for this article. I was thinking of changing my local development environment which is WAMP server installed on my Windows machine.
You can also use Laravel Homestead, which I've found to be incredibly useful
Hi, Thank you for the tutorial. It was super clear and easy to follow.
Keep make tutorial like this, Appreciate it a lot.
I found this very very useful, thank you!
Any tutorial about rest api laravel and mongodb using jwt? I just searching for that lol
I have similar php develop env with docker,
My demo is here demo-docker-compose
Hello, thank you for the great tutorial. Can you help me with migration? i am getting error.
same here, how did you fix this?
You saved my day Andrew! Thank you for sharing your knowledge.
Just wanted to say thanks Andrew for this very detailed an thorough walk through, was amazing!
Thank you for sharing, it works perfect for my project!
The MySQL data will be delete, maybe need set volume data as well as Nginx.
You're right, good suggestion! There's a few good methods I've come across in this thread: stackoverflow.com/questions/391751...
How do u link laravel files when using phpstorm
That's the best part about using this method, you don't have to "link" any files. Just edit them normally like you would any files on your computer, and any changes you make will be available inside the Docker container immediately.
Hey Andrew, there are no folders with the name of container I created what do I miss. But php,mysql and ngnix are up and running with no error.
Fantastic tutorial. It is very clear and thank you. I noticed Laravel Sail has made our life easier with Docker. Perhaps you could update this document (a new thread?) with Sail.
When I run docker-compose exec php php /var/www/artisan migrate
I get error as
Could not open input file: /var/www/artisan