Support the ongoing development of →
posted 1 year ago

elderstar, duch-nuon liked this thread


This is a very interesting topic. I am a complete newbie to docker. I'm also interested in a good way to deploy an existing laravel application developed locally using sail and docker to a production server.

It's also important to be able to easily sync new local files to the production server in the future. I mean rsync on solo or github on a team.

I don't know how to do but my guess is that we will need to create a new docker image by picking out the laravel application from the sail dev environment. Then define the docker images stack we need to create a proper working "prod" environment on the remote server and add a new laravel application image to this stack instead of mounting the application file volumes.

I have read too many different articles and everyone does it in their own way. And I do not have a solid understanding of how to do it in a good way.



Here is the way I go from sail to prod. Special thanks to my brother for his help. and thanks to this article The essence is the same as I described above. In fact, what is missing in the Sail environment, but necessary in the production server? We need a more stable web server. I have taken PHP -FPM + NGINX and going to try RR later.

Here is a sail Dockerfile /vendor/laravel/sail/runtimes/8.1/Dockerfile

And here is my new Dockerfile for prod.

FROM php:8.1-fpm

Arguments defined in docker-compose.yml

ARG user
ARG uid

Install system dependencies

RUN apt-get update && apt-get install -y \
git \
curl \
libpq-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \

Clear cache

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

Install PHP extensions

RUN docker-php-ext-install pdo_pgsql mbstring exif pcntl bcmath gd

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 /var/www

USER $user

next I copied a docker-compose.yml file and change it:

  1. new network instead of sail
  2. changed volumes name, removed sail prefix
  3. added new block nginx:
    image: nginx:alpine
    container_name: app_name-nginx
    restart: unless-stopped
    - ${APP_PORT:-80}:80
    - ./:/var/www
    - ./docker/nginx:/etc/nginx/conf.d\ (create new nginx conf file in the app root dir and mount it) networks:
    - network_name
  4. then the final block app:
    user: user
    uid: 1000
    context: ./
    dockerfile: Dockerfile
    image: app_name
    container_name: app_name-app
    restart: unless-stopped
    working_dir: /var/www/
    - ./:/var/www
    - network_name

So now the app runs apart of the sail and I think it is more suitable for a prod. Moved the app to a prod server and run docker compose up --build


@elderstar, Thanks for the reply


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.