Report this

What is the reason for this report?

Best way to deploy development environment based on docker-compose to production

Posted on January 15, 2021

Below is the docker-compose file of my current development environment for a nest js app. It consists of a nest js api, mysql database. adminer and a nginx reverse proxy. It´s perfect for local development. However, i´struggling to deploy this to digital ocean. How would a setup for production look like?

version: '3.7'

services:

  nest-api:
    build:
      context: server/.
      target: build  
    environment:
      - VIRTUAL_HOST=api.proto.io
      - VIRTUAL_PORT=3000
      - DB_HOST=db
    command: npm run start:dev
    ports:
      - 3000:3000
    volumes:
      - ./server:/usr/src/app
      - /usr/src/app/node_modules
    depends_on:
      - db
    links:
      - db

  db:
    image: mysql:8.0
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=example
      - MYSQL_DATABASE=proto
    volumes:
      - mysqldata:/var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    environment:
      - VIRTUAL_HOST=db.proto.io
      - VIRTUAL_PORT=8080

  nginx:
    container_name: proto-proxy
    image: jwilder/nginx-proxy
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    ports:
      - "8181:80"

volumes:
  mysqldata:



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

What I could suggest here is to use the DigitalOcean App Platform, that way you will not have to do any server configuration and maintenance.

The App Platform also comes with automatic builds and deployments so whenever you push your changes to GitHub, it will automatically trigger a new build and deployment.

Using the App Platform alongside DigitalOcean’s Managed Databases can significantly simplify your deployment process.

Here’s a quick guide for deploying your current setup to DigitalOcean’s App Platform along with a Managed Database:

  1. DigitalOcean Managed Databases:

    • Set up a Managed MySQL Database on DigitalOcean. These managed instances are secure, scalable, and come with automated backups.
    • Once created, take note of the connection credentials.
  2. Modify Your Nest.js App Configuration:

    • Ensure your Nest.js app can use environment variables for database connections so it can connect to the managed database instance. Typically, you’d adjust your app to read from a DATABASE_URL environment variable or similar.
  3. Deploying Nest.js App on DigitalOcean App Platform:

    • Push your Nest.js app to a GitHub or GitLab repository.
    • In DigitalOcean’s App Platform, create a new App.
    • Connect to your GitHub or GitLab account and choose the repository where your Nest.js app resides.
    • During the deploy flow, configure the environment variables required for your app, especially the DATABASE_URL from the managed database.
    • Configure the build and run environment for your Nest.js app. Since it’s a Node.js app, the platform should auto-detect this and make suitable suggestions.
  4. Adminer:

    • If you wish to use Adminer in production (which might not be advisable due to security reasons), you can deploy it as a separate service within the App Platform or use it locally connecting to the managed database using its credentials. Instead, I could suggest using another SQL client like DBeaver for exmaple to access your database.
  5. Domain and HTTPS:

    • Link your domain to the services in the App Platform. The platform automatically provides HTTPS using Let’s Encrypt, ensuring that your traffic is secure.
  6. Continuous Deployment:

    • You can configure App Platform to automatically redeploy your app whenever you push to the main branch of your linked repository. This means that updates can be as simple as just making a git push.
  7. Scaling and Performance:

    • Depending on your application’s requirements, you can easily scale your services in the App Platform. Vertical and horizontal scaling options are available to handle varying levels of traffic.
    • The Managed Database can also be scaled according to your needs.
  8. Monitoring & Logging:

    • DigitalOcean provides built-in monitoring and logging features. Make sure to keep an eye on these for insights into your application’s performance and potential issues.
  9. Backup and Restore:

    • DigitalOcean’s Managed Databases automatically handle backups. Ensure that these backups are scheduled and test the restore process periodically.
  10. Security:

  • Regularly update your application dependencies to receive security patches.
  • The Managed Database and App Platform handle most of the underlying infrastructure security, but always ensure your application logic and dependencies are secure.

Using DigitalOcean’s App Platform and Managed Databases can significantly reduce the operational overhead compared to managing Docker and Docker Compose deployments yourself. This can let you focus more on development and less on infrastructure management.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.