Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FROM php:7.0.4-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
ports:
- "33061:3306"
volumes:
dbdata:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
FROM nginx:1.10
ADD vhost.conf /etc/nginx/conf.d/default.conf
@dporter-nbcuni

This comment has been minimized.

Copy link

commented May 20, 2017

file: docker-compose.yml
database->environment is missing variable - "MYSQL_ROOT_PASSWORD=secret"

@felipefernandes

This comment has been minimized.

Copy link

commented Oct 26, 2017

Hello,

I followed the medium article and I've applied a small fix on line 11 of docker-compose.yml, changing the path on the local machine to use the renamed laravel's folder as my-site folder. I think that it allow isolating the project (laravel) files into a specific folder when the environment setup files still on the root folder.

    volumes:
      - ./my-site:/var/www
@mfour-merickson

This comment has been minimized.

Copy link

commented Dec 30, 2017

I have followed this tutorial and all is working... However, I am trying to connect to MySQL database using Sequel Pro (on Mac) and can't seem to get a connection. DO you happen to know what it would take to get Sequel Pro working?

@Oni-zerone

This comment has been minimized.

Copy link

commented Feb 11, 2018

Not working for me... I'm on mac os x 10.13.3, with Docker CE 17.12.0-ce-mac49.
At the moment, with this exact configuration, it says me
nginx: [emerg] invalid number of arguments in "fastcgi_pass" directive in /etc/nginx/conf.d/default.conf:12
on containers with this exact configuration.
Someone could help me?

@dezigntime

This comment has been minimized.

Copy link

commented Mar 31, 2018

@mfour-merickson I was able to connect with mysqlworkbench
I first ran the below and looked at the network settings
docker inspect <container id>

For my bindings within the "network settings" were set to below

"3306/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "33061"
                    }
                ]

Now back in mysqlworkbench using the below
host : 0.0.0.0
port: 33061
username: root
password: secret

Now this worked for root, was unable to connect as the homestead user

@adibnoh

This comment has been minimized.

Copy link

commented Apr 30, 2018

Hi guys I got this error.

ERROR: In file './docker-compose.yml', volume must be a mapping, not a NoneType.
@ellisgl

This comment has been minimized.

Copy link

commented Jun 13, 2018

Change to php:7.1-fpm to support laravel 5.6 - php:7.2-fpm has too many issues and wont compile.

@dnkodi

This comment has been minimized.

Copy link

commented Aug 9, 2018

@adibnoh make sure the indentation is correct in docker-compose.yml (ex: dbdata should be indented in volumes)

@shojibMahabub

This comment has been minimized.

Copy link

commented Oct 17, 2018

Hello, I followed the post from medium. Everything works fine. But after i write the following commands the development server do not starts at 0.0.0.0:8080 or 127.0.0.1:8000
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan optimize

@aagarwal2286

This comment has been minimized.

Copy link

commented Oct 23, 2018

Hello, I followed the post from medium. Everything works fine. But after i write the following commands the development server do not starts at 0.0.0.0:8080 or 127.0.0.1:8000
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan optimize

Is there any error message on screen. can you share screenshot?

@jbkhellas

This comment has been minimized.

Copy link

commented Nov 6, 2018

Hello, everything runs smoothly BUT all assets on the Laravel installation return a 404 error, any ideas?

@toxab

This comment has been minimized.

Copy link

commented Dec 11, 2018

Hi!

even after
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan optimize
I got 500 error and don't start from
http://127.0.0.1:8080/
http://0.0.0.0:8080/
http://localhost:8080/

and after
docker-compose exec app php artisan migrate --seed
I got error
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'111.11.11.11' (using password: YES) (SQL: select * from information_schema.table
s where table_schema = homestead and table_name = migrations)

[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'111.11.11.11' (using password: YES)

but in .env
and
docker-compose.yml
they mathes

my docker-compose.yml

Begin of docker-compose.yml

version: '2'
services:

The Application

app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:

  • ./:/var/www
    environment:
  • "DB_PORT=3306"
  • "DB_HOST=database"

The Web Server

web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:

  • app
    ports:
  • 8080:80

The Database

database:
image: mysql:5.6
volumes:

  • dbdata:/var/lib/mysql
    environment:
  • "MYSQL_ROOT_PASSWORD=secret"
  • "MYSQL_DATABASE=homestead"
  • "MYSQL_USER=homestead"
    ports:
  • "33061:3306"

volumes:
dbdata:

END OF docker-compose.yml

my .env file

Begin .env file

APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=

I found error after just posted my issue :)
do this
sudo chmod -R 777 storage && sudo chmod -R 777 bootstrap/cache
and m.b. regenerate keys
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan optimize
in my case it works.

@toxab

This comment has been minimized.

Copy link

commented Dec 11, 2018

Hello, everything runs smoothly BUT all assets on the Laravel installation return a 404 error, any ideas?

check where you /app placed
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
in my case from root of app and my folder named e.g. myapp there located all project

I recommended check vhost.conf and docker-compose.yml.
Also, you could compare you files with
https://github.com/shakyShane/laravel-docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.