8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelをLaradockを使わずにDocker環境で開発

Posted at

実現したいこと

  • 下記ミドルウェアを使いたい
    • PHP 7.1
    • MySQL 5.6
    • Redis 2
    • Mailhog
    • Nodejs 8.4
  • PHP-FPMで安定させたい
  • Larvel Dusk ヘッドレスで使いたい
  • WebpackのHMR機能は是が非でも使いたい
  • Linuxじゃない人のことは知りません

他の選択肢

  • Laradock は色々入りすぎてて使いたくない。
  • Homestead はVagrantで重い。
  • Laravel Valet Linuxで開発しているので。

作ったファイル

まずはこれ。log は無くてもいいけど、エラー出しておきたいのでこうした。

docker-compose.yml
version: "2"
services:

  web:
    build: .
    ports:
      - "8000:8000"
      - "9222:9222"
    volumes:
      - "./:/var/www/html"
    working_dir: /var/www/html
    command: "php artisan serve --host 0.0.0.0 --port 8000"
    links:
      - db
      - redis
      - mail
    dns: 8.8.8.8

  db:
    image: mysql:5.6
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: homestead
      MYSQL_USER: homestead
      MYSQL_PASSWORD: secret

  redis:
    image: redis:2
    ports:
      - "6379:6379"

  mail:
    image: mailhog/mailhog
    ports:
      - "8025:8025"

  nodejs:
    image: node:8.4
    ports:
      - "8080:8080"
    volumes:
      - "./:/var/www/html"
    working_dir: /var/www/html
    command: "npm run hot"

  log:
    image: alpine
    volumes:
      - "./:/var/www/html"
    working_dir: /var/www/html
    command: "tail -f storage/logs/laravel.log"

次にこれ。PHP。
Laravel Dusk使いたいので、こうした。 libgconf-2-4 がポイント。

Dockerfile
FROM laradock/php-fpm:1.4-70

RUN apt-get -y update && apt-get -y install chromium libgconf-2-4

artisan 系のタスクは下記で実行する。

docker-compose exec web php artisan dusk

各種設定は

.env
DB_HOST=db
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

とか。

8
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?