MartinZeltin
6 months ago
570
1
General

How to remove Docker volumes for production and COPY instead?

Posted 6 months ago by MartinZeltin

I have a simple Laravel application with Nginx, PHP and MySQL each in its own container. It works great in my development environment but for production I need to remove bind volumes and copy the contents to the image itself instead. But how do I do this?

The rule is that a production container should be immutable

Do I need a seperate docker-compose-prod.yml file? How can I remove volues for production? How can I copy my source code and configuration to the image when deploying for production?

Here is my docker-compose.yml file

version: '3'

networks:
  laranet:

services:
  nginx:
    image: nginx:stable-alpine
    
    container_name: nginxcontainer
    
    ports:
      - "80:80"

    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf

    depends_on:
      - php
      - mysql

    networks:
      - laranet

  mysql:
    image: mysql:5.7.22

    container_name: mysqlcontainer

    ports:
      - "3306:3306"

    volumes:
      - ./mysql:/var/lib/mysql

    networks:
      - laranet

  php:
    build:
      context: .
      dockerfile: php/Dockerfile
    
    container_name: phpcontainer

    volumes:
      - ./src:/var/www/html

    ports:
      - "9000:9000"

    networks:
      - laranet

and here is my php/Dockerfile

FROM php:7.2-fpm-alpine

RUN docker-php-ext-install pdo pdo_mysql
RUN chown -R www-data:www-data /var/www
RUN chmod 755 /var/www

Please sign in or create an account to participate in this conversation.