How to "convert" Docker-Compose into Render.yaml?

Hi there,

I recently Dockerized a Rails app, and I’m having trouble deploying it to Render. I read that Render doesn’t support Docker-Compose.

I’d appreciate it if someone can explain how to convert a Docker-Compose file into a Render.yaml file.
I had a lot of trouble setting up Docker-Compose (still new to it) and I have no idea how to approach converting it in the first place.

Here’s the compose file:

version: '3.8'

services:
  db: &db
    image: 'postgres:14.2-alpine'
    volumes:
      - 'postgres:/var/lib/postgresql/data'
    ports:
      - '5432:5432'
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust

  redis:
    image: 'redis:5-alpine'
    command: redis-server
    ports:
      - '6379:6379'
    volumes:
      - 'redis:/data'

  ws:
    image: anycable/anycable-go:1.2
    ports:
      - '8080:8080'
    environment:
      ANYCABLE_HOST: "0.0.0.0"
      ANYCABLE_REDIS_URL: redis://redis:6379/0
      ANYCABLE_RPC_HOST: anycable:50051
      ANYCABLE_DEBUG: 1
    depends_on:
      - 'redis'

  web: &backend
    depends_on:
      - 'db'
      - 'redis'
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    ports:
      - '3000:3000'
    environment: &backend_environment
      DATABASE_HOST: db
      ANYCABLE_REDIS_URL: redis://redis:6379/0

  anycable:
    <<: *backend
    command: bundle exec anycable
    environment:
      <<: *backend_environment
      ANYCABLE_REDIS_URL: redis://redis:6379/0
      ANYCABLE_RPC_HOST: 0.0.0.0:50051
      ANYCABLE_DEBUG: 1
    ports:
      - '50051'
    depends_on:
      ws:
        condition: service_started

volumes:
  redis:
  postgres:

Hey Chad,

This is entirely untested but should give you some clues,

Dockerfile.anycable:

FROM anycable/anycable-go:1.2
ENV ANYCABLE_RPC_HOST=$RENDER_SERVICE_NAME:50051

render.yaml

databases:
  - name: db # Render PG14
    databaseName: db
    user: dbuser
    postgresMajorVersion: 14

services:
  - type: redis # Render Redis
    name: anycable-redis
    ipAllowList: []

  - type: web
    name: ws
    env: docker
    dockerfilePath: ./Dockerfile.anycable
    envVars:
      - key: ANYCABLE_HOST
        value: "0.0.0.0"
      - key: ANYCABLE_REDIS_URL
        fromService:
          type: redis
          name: redis
          property: connectionString
      - key: ANYCABLE_HOST
        fromService:
          type: web
          name: anycable
          envVarKey: RENDER_SERVICE_NAME #internal address of anycable used in Dockerfile to set ANYCABLE_RPC_HOST
        value: anycable:50051 # need to reference anycable service
      - key : ANYCABLE_DEBUG
        value: 1

  - type: web
    name: web
    env: ruby
    buildCommand: ...
    startCommand: "bundle exec rails s"
    envVars:
      - key: DATABASE_HOST
        fromDatabase:
          type: database
          name: db
          envVarKey: RENDER_SERVICE_NAME
      - key: ANYCABLE_REDIS_URL
        fromService:
          type: redis
          name: anycable-redis
          property: connectionString

  - type: web
    name: anycable
    env: ruby
    buildCommand: ...
    startCommand: bundle exec anycable
    envVars:
      - key: ANYCABLE_REDIS_URL
        fromService:
          type: redis
          name: anycable-redis
          property: connectionString
      - key: ANYCABLE_RPC_HOST
        value: "0.0.0.0:50051"
      - key: ANYCABLE_DEBUG
        value: 1
      - key: PORT
        value: 50051

the ws service would deploy as a docker container, using the Dockerfile which uses the Anycable image and sets the required environment variable.

The web and anycable services will deploy the code that is in your repo, you’ll need to set a buildcommand which for most Rails is bundle install; bundle exec rake assets:precompile.

Hopefully this enough to get you started in the right direction.

1 Like

Hi John!

Thank you for getting back to me and for converting the Compose to a Render file.
It clears up so many questions, as I’m able to make direct comparisons and see the purpose of each line.

I do have one more question. There is no way to run Render.yaml file locally, am I correct? Like how you’d be able to do with the docker-compose file.

Thanks again for your help. I need to get an app deployed within the week. This pointed me in the right direction.

Chad, you’re most welcome - we’re here to help when you need us.

As for running the render.yaml locally - we don’t have anything official but https://twitter.com/JonasScholz19/status/1523727735763648512?s=20&t=2IxCaNWhAZZf2Z0iZiL6hw from one of our customers looks interesting when it gets released.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.