|
1 | 1 | # Docker Development Environment |
2 | 2 |
|
| 3 | +>This is also documented at [UserFrosting Learn](https://learn.userfrosting.com/installation/environment/docker). |
| 4 | +
|
3 | 5 | First, install [Docker Compose](https://docs.docker.com/compose/install/). |
4 | 6 |
|
5 | 7 | Second, initialize a new UserFrosting project: |
6 | | -1. Clone the repository `git clone https://github.com/userfrosting/UserFrosting.git .` and change into that directory `cd userfrosting` |
7 | | -1. Run `cp app/sprinkles.example.json app/sprinkles.json` or upload your own (also upload your sprinkles if you have some) |
8 | | -2. Run `sudo chown -R 33 app/{logs,cache,sessions}` (Changes the user to the www-data user of the image, more information [here](https://serversforhackers.com/c/dckr-file-permissions) ) |
9 | | -2. Run `sudo docker-compose run composer install` to install all composer modules. |
10 | | -3. Run `sudo docker-compose run node npm install` to install all npm modules. |
| 8 | + |
| 9 | +1. Copy `app/sprinkles.example.json` to `app/sprinkles.json` |
| 10 | +2. Run `chmod 777 app/{logs,cache,sessions}` to fix file permissions for web server. (NOTE: File |
| 11 | + permissions should be properly secured in a production environment!) |
| 12 | +3. Run `docker-compose run composer install --ignore-platform-reqs --no-scripts` to install all composer modules. (https://hub.docker.com/_/composer) Sometimes dependencies or Composer scripts require the availability of certain PHP extensions. You can work around this as follows: Pass the `--ignore-platform-reqs and --no-scripts` flags to install or update |
| 13 | +4. Run `docker-compose run node npm install` to install all npm modules. |
| 14 | +5. Run `docker-compose run composer update --ignore-platform-reqs --no-scripts` to install remaining composer modules |
| 15 | +6. Run `docker-compose run node npm run uf-assets-install` to install all frontend vendor assets. |
11 | 16 |
|
12 | 17 | Now you can start up the entire Nginx + PHP + MySQL stack using docker with: |
13 | 18 |
|
14 | | - $ sudo docker-compose up -d |
| 19 | + $ docker-compose up -d |
| 20 | + |
| 21 | +the `-d` flag will launch this in the background so you can continue to use the terminal window. On the first run you need to init the database (your container name may be different depending on the name of your root directory): |
| 22 | + |
| 23 | + $ docker exec -it -u www-data userfrosting_php_1 sh -c 'php bakery migrate' |
15 | 24 |
|
16 | | -On the first run you need to init the database (Be sure to execute this in the same directory, `${PWD##*/}` is a statement to get your current working directorys name. Docker uses it to name your container): |
| 25 | +You also need to setup the first admin user (again, your container name may be different depending on the name of your root directory): |
17 | 26 |
|
18 | | - $ sudo docker exec -it -u www-data ${PWD##*/}_php_1 bash -c 'php bakery migrate' |
19 | | - |
20 | | -You also need to setup the first admin user (again, `${PWD##*/}` is a statement to get your current working directorys name): |
| 27 | + $ docker exec -it -u www-data userfrosting_php_1 sh -c 'php bakery create-admin' |
21 | 28 |
|
22 | | - $ sudo docker exec -it -u www-data ${PWD##*/}_php_1 bash -c 'php bakery create-admin' |
| 29 | +Now visit `http://localhost:8591/` to see your UserFrosting homepage! |
23 | 30 |
|
24 | | -Now visit http://localhost:8570/ to see your UserFrosting homepage! |
| 31 | +**Paste these into a bash file and execute it!** |
25 | 32 |
|
26 | | -**This is not (yet) meant for production!!** |
| 33 | +``` |
| 34 | +chmod 777 app/{logs,cache,sessions} |
| 35 | +docker-compose build --force-rm --no-cache |
| 36 | +docker-compose run composer install --ignore-platform-reqs --no-scripts |
| 37 | +docker-compose run node npm install |
| 38 | +docker-compose run composer update --ignore-platform-reqs --no-scripts |
| 39 | +docker-compose run node npm run uf-assets-install |
| 40 | +docker-compose up -d |
| 41 | +echo -n "Enter Docker Container Name --> " |
| 42 | +read docker_container |
| 43 | +docker exec -it -u www-data $docker_container sh -c 'php bakery migrate' |
| 44 | +docker exec -it -u www-data $docker_container sh -c 'php bakery create-admin' |
| 45 | +``` |
| 46 | + |
| 47 | +**This is not (yet) meant for production!** |
27 | 48 |
|
28 | 49 | You may be tempted to run with this in production but this setup has not been security-hardened. For example: |
29 | 50 |
|
30 | | -- Database is exposed on port 8571 so you can access MySQL using your favorite client at localhost:8571. However, |
| 51 | +- Database is exposed on port 8593 so you can access MySQL using your favorite client at localhost:8593. However, |
31 | 52 | the way Docker exposes this actually bypasses common firewalls like `ufw` so this should not be exposed in production. |
32 | 53 | - Database credentials are hard-coded so obviously not secure. |
33 | 54 | - File permissions may be more open than necessary. |
| 55 | +- HTTPS not implemented fully |
34 | 56 | - It just hasn't been thoroughly tested in the capacity of being a production system. |
35 | | - |
36 | | -## Updating your code |
37 | | -As you might guessed you will have to run |
38 | | - |
39 | | - $ sudo docker exec -it -u www-data userfrosting_php_1 bash -c 'php bakery migrate' |
40 | | - |
41 | | -again if you want to migrate tables. |
42 | | -You can change `php bakery migrate` to other `bakery` commands as well. |
43 | | -Be aware that the userfrosting container doesn't know about npm! |
44 | | -Similary for composer: |
45 | | - |
46 | | - $ sudo docker-compose run composer update |
47 | | - |
48 | | -See the [Docker](https://docs.docker.com/engine) and [Docker-compose documentation](https://docs.docker.com/compose/) for more details. |
|
0 commit comments