creating a separate docker-compose configuration for production and development
Asked Answered
C

2

5

I have a docker-compose setup for development, and I need to replicate the same file for production or staging.

Currently, aside from volumes ports and environment I am not quite sure what settings "may need" to be changed for production/environment.

To clarify:

  • I have to change volumes, because I usually mount a USB drive to my docker container ex: d:/var/www
  • The issue with ports is, because there may be other services that use port 80 on my local machine, so I may need to change that.
  • environment is of course, different for prod/dev .. (mainly authentication and database access)

Any more tips would be nice to know.

Conni answered 10/10, 2018 at 16:59 Comment(0)
G
3

The exact list would depend on your environment/ops team requirements, but this is what seems to be useful besides ports/existing volumes:

Networks

The default network might not work for your prod environment. As an example, your ops team might decide to put nginx/php-fpm/mariadb on different networks like in the following example (https://docs.docker.com/compose/networking/#specify-custom-networks) or even use a pre-existing network

Mysql configs

They usually reside in a separate dir i.e. /etc/my.cnf and /etc/my.cnf.d. These configs are likely to be different between prod/dev. Can’t see it in your volumes paths

Php-fpm7

Haven’t worked with php-fpm7, but in php-fpm5 it also had a different folder with config files (/etc/php-fpm.conf and /etc/php-fpm.d) that is missing in your volumes. These files are also likely to differ once your handle even a moderate load (you’ll need to configure number of workers/timeouts etc)

Nginx

Same as for php-fpm, ssl settings/hostnames/domains configurations are likely to be different

Logging

Think on what logging driver might fit your needs best. From here:

Docker includes multiple logging mechanisms to help you get information from running containers and services. These mechanisms are called logging drivers.

You can easily configure it in docker-compose, here's an example bring up a dedicated fluentd container for logging:

version: "3"

services:
  randolog:
    image: golang
    command: go run /usr/src/randolog/main.go
    volumes:
      - ./randolog/:/usr/src/randolog/
    logging:
      driver: fluentd
      options:
        fluentd-address: "localhost:24224"
        tag: "docker.{{.ID}}"

  fluentd:
    build:
      context: ./fluentd/
    ports:
      - "24224:24224"
      - "24224:24224/udp"
Gunnery answered 19/10, 2018 at 20:3 Comment(0)
M
1

You should follow the Use Compose in production documentation:

You probably need to make changes to your app configuration to make it ready for production. These changes may include:

  • Removing any volume bindings for application code, so that code stays inside the container and can’t be changed from outside
  • Binding to different ports on the host
  • Setting environment variables differently, such as when you need to decrease the verbosity of logging, or to enable email sending)
  • Specifying a restart policy like restart: always to avoid downtime

  • Adding extra services such as a log aggregator

Merriweather answered 16/10, 2018 at 14:44 Comment(1)
I have read the docs, point two and five are a little vague and the doc is far from comprehsive, that is why I asked the questionConni

© 2022 - 2024 — McMap. All rights reserved.