Streamlining macOS Development with OrbStack: Docker, Linux VMs, and Seamless Integration

This guide explores how to leverage OrbStack to create a robust and efficient development environment on macOS, particularly beneficial for machines with ARM chips (M1/M2). We’ll cover setting up Docker containers, creating an amd64 Linux virtual machine, and integrating everything seamlessly with your existing tools.

What We’ll Cover:

  1. OrbStack Installation: A streamlined process for getting OrbStack up and running.
  2. Docker Containerization: Deploying essential services like PostgreSQL and Redis using Docker Compose within OrbStack.
  3. Creating an amd64 Linux VM: Addressing compatibility issues by running an x86_64 virtual machine.
  4. Setting Up the Development Environment: Installing dependencies, Mise (version manager), Ruby, and Rails within the VM.
  5. Seamless Workflow Integration: Using your terminal, browser, and VS Code as if everything were running locally.

1. Installing OrbStack

OrbStack provides a lightweight environment for running Docker and Linux VMs on macOS, optimizing performance, especially on ARM-based systems.

Download and Installation Steps:

  1. Download the latest version of OrbStack.
  2. Open the downloaded .dmg file.
  3. Drag the OrbStack application to your “Applications” folder.
  4. Launch OrbStack and follow the on-screen setup instructions.

Verification

To confirm a successful installation, open your Terminal and run:

orb version

You should see the installed OrbStack version displayed. For a complete list of OrbStack commands, use:

orb help

2. Running Containers with PostgreSQL and Redis

OrbStack includes built-in Docker support, allowing you to run containers directly without complex configuration.

Setting up Docker Compose for PostgreSQL and Redis

First, create a directory to organize your service configurations:

mkdir -p ~/orbstack-services && cd ~/orbstack-services

Next, create a docker-compose.yml file within this directory with the following content:

version: "3.8"

services:
  postgres:
    image: postgres:latest
    container_name: postgres
    restart: always
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: mydb
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  redis:
    image: redis:latest
    container_name: redis
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data

volumes:
  postgres_data:
  redis_data:

This configuration defines two services: a PostgreSQL database and a Redis instance. It specifies ports, environment variables, and persistent volumes to ensure data durability.

Launching the Containers

To start the containers, run:

docker-compose up -d

The -d flag runs the containers in detached mode (in the background). You now have PostgreSQL accessible on port 5432 and Redis on port 6379.

To verify that the containers are running, use:

docker ps

To stop the services:

docker-compose down

3. Creating an amd64 Linux Virtual Machine

While macOS M1/M2 chips use the ARM64 architecture, some software requires the amd64 (x86_64) architecture. OrbStack allows you to create and run an amd64 VM effortlessly.

Creating the amd64 VM

Run the following command in your terminal:

orb create -a amd64 ubuntu linux-amd64 --set-password yourpassword

Important: Replace yourpassword with a secure password that you will remember. This command creates an Ubuntu virtual machine with the amd64 architecture.

Starting and Accessing the VM

To start the VM:

orb start linux-amd64

To access the VM’s shell:

orb shell linux-amd64

You are now inside a Linux environment compatible with amd64 software, circumventing potential compatibility issues on your ARM-based macOS.

Verifying the Architecture

Inside the VM, run:

uname -a

The output should confirm the x86_64 architecture.
You can see the OrbStack help using:

orb help

4. Setting Up the Development Environment (Mise, Ruby, Rails)

Before installing Mise and Ruby, we need to install the necessary dependencies.

Installing Dependencies

Within the OrbStack VM’s shell, execute the following commands:

sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev \
  libsqlite3-dev libffi-dev libgdbm-dev libncurses5-dev libyaml-dev \
  libgmp-dev libgmp3-dev autoconf bison

These commands update the package list, upgrade existing packages, and install the required build tools and libraries for Ruby.

Installing Mise

Mise is a versatile tool for managing runtime versions. Install it within the VM using:

curl https://mise.run | sh
exec $SHELL

Verify the installation:

mise --version

Installing Ruby

Install Ruby using Mise:

mise install ruby

Set the latest Ruby version as the global default:

mise use -g ruby latest

Verify the Ruby installation:

ruby -v

Installing Rails

Install the Rails gem:

gem install rails

Verify the Rails installation:

rails -v

You now have Ruby and Rails installed and configured within your amd64 Linux VM.

5. Seamless Workflow Integration

Terminal Access

You can access the VM from your macOS terminal using:

orb shell linux-amd64

To start a Rails server, you would typically navigate to your project directory within the VM and run rails s. You can then access the application in your macOS browser at `http://localhost:3000`.

VS Code Integration

For a seamless code editing experience, install the “Remote – SSH” extension in VS Code. This allows you to connect to the VM via SSH and work on your project files as if they were local.

Alternatively, from within the project directory in the VM’s shell, you can use:

code .

This will open the current project in VS Code, leveraging the Remote – SSH extension for a smooth development workflow.

Conclusion

You’ve now established a comprehensive development environment using OrbStack, encompassing:

  • Docker containers for PostgreSQL and Redis, providing essential services.
  • An amd64 Ubuntu virtual machine, ensuring compatibility with a wider range of software.
  • Ruby and Rails installed and managed with Mise.
  • Seamless integration with your terminal, browser, and VS Code, creating a unified development experience.

To remove the VM:

orb delete linux-amd64

To stop the Docker containers:

docker-compose down

Your robust and flexible development environment is now ready!

Innovative Software Technology: Optimizing Your macOS Development Workflow

At Innovative Software Technology, we specialize in crafting optimized and efficient development environments tailored to your specific needs. If you’re struggling with macOS compatibility issues, slow Docker performance, or complex VM setups, we can help. Our expertise in OrbStack, Docker, Linux VMs, and development toolchains (Ruby, Rails, Mise, etc.) ensures a fast, reliable, and SEO-friendly development workflow. We provide solutions that boost developer productivity, improve application performance, and ensure seamless cross-platform compatibility. Contact us today to learn how we can streamline your development process, reduce bottlenecks, and enhance your overall software development lifecycle. We focus in keywords like: macOS Development Optimization, OrbStack Consulting, Docker Performance Tuning, Linux VM for Mac, Ruby on Rails Development Services, amd64 on M1/M2 Mac, Software Development Efficiency, and Cross-Platform Development Solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed