Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2017 11:02
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 32 You must be signed in to fork a gist
  • Save anonymous/a13cf604981726c8e8b0bb05a35664e2 to your computer and use it in GitHub Desktop.
Save anonymous/a13cf604981726c8e8b0bb05a35664e2 to your computer and use it in GitHub Desktop.
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
@dnkodi
Copy link

dnkodi commented Aug 9, 2018

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

@shojibMahabub
Copy link

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
Copy link

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
Copy link

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

@toxab
Copy link

toxab 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
Copy link

toxab 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