Skip to content

Instantly share code, notes, and snippets.

@TimoDJatomika
Last active March 19, 2020 15:04
Show Gist options
  • Save TimoDJatomika/a8f81ef2b22a7e81af0de5b36b9fbfaf to your computer and use it in GitHub Desktop.
Save TimoDJatomika/a8f81ef2b22a7e81af0de5b36b9fbfaf to your computer and use it in GitHub Desktop.
How to work with Laravel and Docker

Using Laravel and Docker

by Timo Stankowitz [email protected]

If you have any questions of any suggestions just reach out to me.

create a new project with composer

Don't create an extra directory. Comperser will do this for you. The folder name will be project-name (change to your actual project name).

docker run -u 1000 ---rm -v $(pwd):/app composer/composer create-project --prefer-dist laravel/laravel *project-name*

This can take you up to 5 minutes.

create an .env file

cp .env.example .env You can copy and paste the first part of the example file.

create an application encryption key

This is required. Otherwise your application will not start. Use php artisan for that:

docker run --rm -v $(pwd):/mount php php /mount/artisan key:generate

set the currect folder permission

upcomming

start your application with artisan

The simplest way is to create a Dockerfile in you root directory with touch Dockerfile. Copy and paste the following content:

FROM php
LABEL maintainer="Timo Stankowitz <[email protected]>"

COPY ./ /mount

WORKDIR /mount

ENTRYPOINT ["php", "artisan", "serve"]

Per default your application will run on port 8000. Just go to http://localhost:8000 to check if your application is running.

If you want to change the port just replace the list line with this: ENTRYPOINT ["php", "artisan", "serve", "--port=80"]. In this example your port will be 80.

create docker-compose.yml

version: '3'
services:
  project-name:
    build: .
    network_mode: 'host'
    volumes:
      - ./:/mount

and run docker-compose up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment