The easiest way to setup docker for Symfony or Laravel

Docker is a handy tool to setup multiple light-weight development environments or to virtualize your server.

Too bad, docker has a steep learning curve and demands you to know some ops-stuff, certainly when docker up doesn’t docker up, but shows an obscure error message instead 🙂

In order to avoid these time-consuming setups, you can use the preconfigured docker compose libraries from DockerWest (github).

I’m not a docker-specialist, far from it, but these libraries always work for me, and don’t require much configuration. In my eyes, they are the easiest way to get a php-docker up and running.

Each ‘setup’ consists of several docker containers that communicate together. There’s an nginx, mailcatcher, mysql, redis and php (application) container.

This manual applies for Ubuntu (or other Linux distributions).

DockerWest provides docker environments for:

  • Laravel 5
  • Symfony 3 + 4
  • Magento 2
  • Pimcore 4 + 5

Install DockerWest

Make sure you’ve installed docker and docker-compose before you continue with this tutorial.

1) Clone the repo you need, in this example: Symfony

git clone https://github.com/dockerwest/compose-symfony

2) Navigate to the newly created folder

cd compose-symfony

3) Rename the .env-sample file

mv .env-sample .env

4) Edit the .env file

vim .env

Configure DockerWest

Setup the correct parameters in the .env file. Most of the options speak for themselves. I listed the most important options:

C_UID and C_GID

Type the user-id and group-id that the container must use. It’s easiest if they match your user account.

To find your local UID you can run id -u and to find your local GID you can run id -g.

PHPVERSION

How do I know which PHP version to choose?
You can choose between these php versions.
For a local environment, it’s best to use the PHP version that runs on your server. If it’s just to toy around, use the most recent version.

BASEHOST & EXTRAHOST

These are the local domains you want to access the website from. These domains (+ their IP’s) must be configured in /etc/hosts.

APPLICATION

The relative path to the wwwroot on your host machine.

6) Save the file and exit (escape+ :wq + enter in Vim)

7) Run ./environment

Environment allows you to start your environment with an updated PATH
This opens a tmux window (install tmux if you don’t have this on your system)

8) Say a little prayer and type:

run up

This will pull and install the docker boxes. Once it stalls and displays this you’re all set 🙂

application_1  | 127.0.0.1 -  02/Jun/2019:14:10:59 +0000 "GET /ping" 200

Navigate in your browser to the host-url you’ve setted in the .env file.

‘Inside’ the docker container

If you want to ‘enter’ the docker box, you can using tmux. If you’re in the ./environmentwindow,
type: ctrl + b, followed by c
This enters a new ‘tab’ inside your tmux.

To go back to the previous screen, type: ctrl + b, followed by 1 (the number of the tab).

Framework commands

Once you’re in the environment, you can use the commands from Laravel, Symfony or whatever you use.

Mysql

If you want to access the database, just type mysql in the tmux console. It will auto direct you to the docker mysql instance. You can also use mysqlimport (with a file on your host machine!).

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.