[Docker] Fix issues with PostgreSQL and move docker-compose file to root

This commit is contained in:
Alex Thomassen 2020-04-02 16:09:19 +02:00
parent c33f7974e4
commit 8e19811b0f
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
8 changed files with 29 additions and 21 deletions

1
.docker/.gitignore vendored
View File

@ -1 +0,0 @@
docker-compose.yml

View File

@ -14,13 +14,14 @@ RUN apt-get update && apt-get install -y \
libonig-dev \
libxml2-dev \
zip \
unzip
unzip \
libpq-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd pgsql pdo_pgsql
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

View File

@ -12,25 +12,30 @@
1. Download the project repository via Git: `git clone https://git.alex.lol/FLOT/HovedprosjektWebApp.git /srv/FLOTWebApp`
2. Navigate to the repository directory: `cd /srv/FLOTWebApp`
3. Copy `.env.example` to `.env`. Leave the `.env` file as is for now.
4. Navigate to the `.docker` directory in the repository.
5. Copy `docker-compose.example.yml` to `docker-compose.yml`.
6. Edit `docker-compose.yml` (with your text editor) and modify configuration/volumes to match your needs.
7. Copy `nginx/hovedprosjekt.example.conf` to `nginx/hovedprosjekt.conf`.
8. Edit `nginx/hovedprosjekt.conf` and modify domain/TLS configuration to your needs.
- Make sure that the SSL certificate and key uses the path as the volume mapping in `docker-compose.yml`.
8. Edit `../.env` and modify your database credentials to match the ones you set in `docker-compose.yml`
4. Copy `docker-compose.example.yml` to `docker-compose.yml`.
5. Edit `docker-compose.yml` (with your text editor) and modify configuration/volumes to match your needs.
6. Edit `../.env` and modify your database credentials to match the ones you set in `docker-compose.yml`
- `DB_HOST` (db) and `DB_PORT` (5432) can generally be left as is
9. Run `docker-compose build app`
10. If built successfully, run `docker-compose up -d` to run all containers in "detached" mode.
7. Navigate to the `.docker` directory in the repository.
8. Copy `examples/hovedprosjekt.example.conf` to `nginx/hovedprosjekt.conf`.
9. Edit `nginx/hovedprosjekt.conf` and modify domain/TLS configuration to your needs.
- Make sure that the SSL certificate and key uses the path as the volume mapping in `docker-compose.yml`.
10. Run `docker-compose build app`
11. If built successfully, run `docker-compose up -d` to run all containers in "detached" mode.
## Application setup - First-time setup only
These steps should be run after you have run `docker-compose up -d`, as the containers need to be running.
1. While still being in the `.docker` directory run: `docker-compose exec app composer install`
1. Go to the project repository: `cd /srv/FLOTWebApp`
2. Make sure that the project repository has correct permissions for the user specified in `docker-compose.yml`
- `sudo chown -R 1000: .` will set it to the user with ID "1000". You can see users and their IDs if you `cat /etc/passwd`.
3. While still being in the `.docker` directory run: `docker-compose exec app composer install`
- This will attach the `app` container and run the following command to install dependencies for the application: `composer install`
- Dependency installation might take a while, so be patient.
2. Then run: `docker-compose exec app php artisan key:generate` to generate an app key that's saved in `.env`
4. Run `docker-compose exec app php artisan key:generate` to generate an app key that's saved in `.env`
5. Finally, create the database tables with: `docker-compose exec app php artisan migrate`
6. [Optional] Add sample users and posts to the database tables: `docker-compose exec app php artisan db:seed`
## Logs [Optional]

2
.docker/examples/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.conf
!*.example.conf

View File

@ -1,2 +1,2 @@
*.conf
!*.example.conf
*
!.gitignore

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
docker-compose.yml

View File

@ -6,14 +6,14 @@ services:
args:
user: hovedprosjekt
uid: 1000
context: ./
context: ./.docker
dockerfile: Dockerfile
image: hovedprosjekt
container_name: hovedprosjekt-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ../:/var/www
- ./:/var/www
networks:
- hovedprosjekt
@ -22,7 +22,7 @@ services:
container_name: hovedprosjekt-db
restart: unless-stopped
environment:
POSTGRES_PASSWORD: FLOTHP_D8jqH4YjS4ajD4
POSTGRES_PASSWORD: FLOT_Hovedprosjekt
POSTGRES_USER: hovedprosjekt
POSTGRES_DB: hovedprosjekt
volumes:
@ -38,8 +38,8 @@ services:
- 80:80
- 443:443
volumes:
- ../:/var/www
- ./nginx/:/etc/nginx/conf.d/
- ./:/var/www
- ./.docker/nginx/:/etc/nginx/conf.d/
- /srv/ssl:/srv/ssl
networks:
- hovedprosjekt