Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alessandrobelli's avatar

Docker, Laravel and a production server with apache running

Hello! I'm doing a project in which I need to go to production in a server that in currently running php 7.0.* and it's not possible to upgrade due to old software. Docker was already installed to ensure onlyoffice could run. Now I would like to have multiple laravel project at the same time, but I can't figure out a way or a guide that helps me. The laradock guide is helpful to start and get a working image, but where I can see if laradock will mess the current docker images?

0 likes
10 replies
ohffs's avatar

I'm running stuff on our staging server just now doing this (we've not been quite brave enough to push the setup to production though). We've got :

  • a docker-compose.yml file for each app that sets up the app, scheduler, queues and adds some keys for -
  • traefik which takes care of routing incoming requests to the correct containers.

Our dockerfile setup is based on the idea from this laravel news article.

Our docker-compose.yml file ends up like this :

version: "3"
services:
  app:
    image: localhost:5000/someapp-web
    container_name: someapp-web
    build:
      context: .
      dockerfile: docker/Dockerfile
    depends_on:
      - redis
      - mysql
    networks:
      - proxy
      - private
    expose:
      - "80"
    environment:
      APP_ENV: local
      CONTAINER_ROLE: app
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_DATABASE: someapp2
      DB_USERNAME: homestead
      DB_PASSWORD: secret
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      QUEUE_DRIVER: redis
      REDIS_HOST: redis
      DEFAULT_DISK: images
    deploy:
      replicas: 3
      labels:
        - "traefik.backend=someapp-web"
        - "traefik.docker.network=proxy"
        - "traefik.frontend.rule=Host:someapp.staging.our.domain.com"
        - "traefik.enable=true"
        - "traefik.port=80"
        - "traefik.default.protocol=http"

  scheduler:
    image: localhost:5000/someapp-web
    container_name: someapp-scheduler
    depends_on:
      - app
    deploy:
      labels:
        - "traefik.enable=false"
    networks:
      - private
    environment:
      APP_ENV: local
      CONTAINER_ROLE: scheduler
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_DATABASE: someapp2
      DB_USERNAME: homestead
      DB_PASSWORD: secret
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      QUEUE_DRIVER: redis
      REDIS_HOST: redis
      DEFAULT_DISK: images

  queue:
    image: localhost:5000/someapp-web
    container_name: someapp-queue
    depends_on:
      - app
    deploy:
      replicas: 2
      labels:
        - "traefik.enable=false"
    networks:
      - private
    environment:
      APP_ENV: local
      CONTAINER_ROLE: queue
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_DATABASE: someapp2
      DB_USERNAME: homestead
      DB_PASSWORD: secret
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      QUEUE_DRIVER: redis
      REDIS_HOST: redis
      DEFAULT_DISK: images

  redis:
    container_name: someapp-redis
    image: redis:4
    deploy:
      labels:
        - "traefik.enable=false"
    networks:
      - private
    volumes:
      - redis:/data

  mysql:
    container_name: someapp-mysql
    image: mysql:5.7
    deploy:
      labels:
        - "traefik.enable=false"
    networks:
      - private
    volumes:
      - mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: someapp2
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: homestead
      MYSQL_PASSWORD: secret

volumes:
  redis:
    driver: "local"
  mysql:
    driver: "local"

networks:
  private:
  proxy:
    external: true

1 like
goatshark's avatar

@alessandrobelli I wouldn't call this "comprehensive", but I've been working on this and using it (in it's incomplete state) for a while.... https://github.com/goatatwork/LaravelDocker

Maybe it'll give you some ideas. Btw, I recently swapped out the php7.0 container for a php7.2 container. If I hadn't have been sold on containers before then (I was), I would have been when I did NOT have to deal with upgrading php on the OS. Wow.

1 like
alessandrobelli's avatar

@ohffs I'm trying out your docker-compose.yml but I get this error:

Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

Then, if I change it to 2 I get this:

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.app: 'deploy'
Unsupported config option for services.mysql: 'deploy'
Unsupported config option for services.queue: 'deploy'
Unsupported config option for services.redis: 'deploy'
Unsupported config option for services.scheduler: 'deploy'
ohffs's avatar

@ALESSANDROBELLI - I think that means you are on an older version of docker/docker-compose. I think you need docker-compose 1.21+ (and a recent-ish (v17+) docker itself) to do all the newer 'deploy' stuff that traefik uses. Try running docker-compose --version and docker --version to check which you are running.

alessandrobelli's avatar

@OHFFS -

docker --version
Docker version 18.06.1-ce, build e68fc7a
docker-compose --version
docker-compose version 1.8.0, build f3628c7

these should be right, right?

ohffs's avatar

@ALESSANDROBELLI - Your docker-compose is 1.8? I think you'll have to update it to a newer version - the current one is 1.23 :-)

alessandrobelli's avatar

@OHFFS - mmmmmmmm but isn't 1.8 > 1.23 ? How is the versioning working? :O

anyway thanks a lot, really, but I asked the boss to bring some external expertise to create a docker on the server. I'm currently the only developer and if I focus on docker all the time plan shift a lot.

goatshark's avatar

@alessandrobelli docker and docker-compose are installed separately; two different packages. That's why their version numbers are so wildly different.

Good luck with your docker project.

1 like
ohffs's avatar

@ALESSANDROBELLI - Not in version number terms - is 'version 1, release number 8' greater than 'version 1, release number 23' :-)

Hope your boss gets someone to help :-) I found this video series really helpful to get up and running with it - if your boss wants to pay out a little money : https://serversforhackers.com/shipping-docker

1 like

Please or to participate in this conversation.