I know tons of questions have been asked on this topic, I read a lot of them but each time something isn't exactly as I need it and I don't manage to get it working.
I have a project that I need to deploy to a server. I want to have this containerized to enable easy auto deployment. I have a server installed with Docker and I use Watchtower to watch for updated frontend
and backend
.
My project consists of:
Laravel backend:
This project has it's own GitLab repository. On pushing to the release branch GitLab CI/CD creates a Docker container based on the following Dockerfile and pushes it to DockerHub.
Dockerfile
Of course I don't want to keep running it using php artisan serve
but at the moment it's the best I could do.
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user=user
ARG uid=1000
# Install system dependencies
RUN apt-get update && apt-get install -y
libldap2-dev
zip
unzip
git
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/
RUN docker-php-ext-install pdo_mysql exif pcntl bcmath ldap
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer &&
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /app
COPY . /app
RUN chown -R $user /app
USER $user
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000
.gitlab-ci.yml
docker-build-master:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build --pull -t "$CI_REGISTRY_IMAGE" .
- docker push "$CI_REGISTRY_IMAGE"
only:
- release
VueJS frontend:
This project has it's own GitLab repository. On pushing to the release branch GitLab CI/CD creates a Docker container based on a similar Dockerfile and pushes it to DockerHub. The dockerfile and .gitlab-ci.yml files for the frontend are similar to those of the backend, just different image and different packages.
The quesion
How do I tie this all together to run on the server? I read the backend
image needs nginx as well to actually run the Laravel application? How do I do this and how do I configure it? Does the frontend
image need nginx as well? How do I add MySQL to the whole setup as soon as both the frontend and backend container are deployed to the server? How do I take care of the routing of requests to either backend (https://api.application.example/v1/<API_ENDPOINT_URI>) or frontend (https://www.application.example/)?
Thanks a lot for taking the time to read this and answer my questions!
question from:
https://stackoverflow.com/questions/66061260/how-to-use-docker-with-laravel-vuejs-mysql-and-web-server 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…