最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Rails devcontainer doesn't have ruby and bundler installed - Stack Overflow

programmeradmin5浏览0评论

I'm getting this error when trying to start the dev container.

[2025-03-19T16:39:10.740Z] Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "bundle": executable file not found in $PATH: unknown

If I hop into the container and check for executables, I don't see any related to ruby or bundler.

root ➜ / $ bundle
bash: bundle: command not found
root ➜ / $ gem
bash: gem: command not found
root ➜ / $ ruby
bash: ruby: command not found

I started going down the path of installing an official ruby image but I shouldn't need to with devcontainers. This is for an existing project but the complexity of services is quite minimal.

Here are my configs. I hope it's something obvious.

Dockerfile

ARG RUBY_VERSION=3.4.2
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION

# Install packages needed to build gems
RUN apt-get update -qq \
    && apt-get install --no-install-recommends -y \
    build-essential \
    libpq-dev \
    libvips \
    curl \
    imagemagick \
    postgresql-client \
    nodejs \
    vim \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

compose.yml

name: "escrow_safe"
services:
  web:
    build:
      dockerfile: .devcontainer/Dockerfile
      context: ..
    ports:
      - "3000:3000"
      - "12345:12345"
    command: sleep infinity
    environment:
      - ES_DEV_PHONE_OVERRIDE
      - DEV_EMAIL_PREFIX=${USER}
      - DATABASE_URL=postgres://root:password@postgres-db/
      - EDITOR=vim
      - ES_DEBUG_ENABLED=true
    volumes:
      - ../..:/workspaces:cached
    depends_on:
      postgres-db:
        condition: service_healthy

  solidq:
    build:
      dockerfile: .devcontainer/Dockerfile
      context: ..
    command: bundle exec rails solid_queue:start
    environment:
      - DATABASE_URL=postgres-db://root:password@postgres-db/
    volumes:
      - ../..:/workspaces:cached
      # - bundler_gems:/usr/local/bundle
    depends_on:
      postgres-db:
        condition: service_healthy

  postgres-db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: password
    volumes:
      - db_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: pg_isready
      interval: 2s
      timeout: 5s
      retries: 30

volumes:
  db_data:

devcontainer.json

{
  "name": "escrow_safe",
  "dockerComposeFile": "compose.yaml",
  "service": "web",
  // "workspaceFolder": "/rails",
  "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
  // Features to add to the dev container. More info: /features.
  "features": {
    "ghcr.io/devcontainers/features/github-cli:1": {},
    "ghcr.io/rails/devcontainer/features/activestorage": {},
    "ghcr.io/rails/devcontainer/features/postgres-client": {},
    "ghcr.io/rails/devcontainer/features/bundler-cache:1": {}
  },
  "containerEnv": {
    "CAPYBARA_SERVER_PORT": "45678",
    "SELENIUM_HOST": "selenium",
    "DB_HOST": "postgres"
  },
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  "forwardPorts": [
    3000,
    5432,
    6379
  ],
  // Configure tool-specific properties.
  // "customizations": {},
  // Uncomment to connect as root instead. More info: .
  // "remoteUser": "root",
  // Use 'postCreateCommand' to run commands after the container is created.
  "postCreateCommand": "bin/setup"
}

I'm getting this error when trying to start the dev container.

[2025-03-19T16:39:10.740Z] Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "bundle": executable file not found in $PATH: unknown

If I hop into the container and check for executables, I don't see any related to ruby or bundler.

root ➜ / $ bundle
bash: bundle: command not found
root ➜ / $ gem
bash: gem: command not found
root ➜ / $ ruby
bash: ruby: command not found

I started going down the path of installing an official ruby image but I shouldn't need to with devcontainers. This is for an existing project but the complexity of services is quite minimal.

Here are my configs. I hope it's something obvious.

Dockerfile

ARG RUBY_VERSION=3.4.2
FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION

# Install packages needed to build gems
RUN apt-get update -qq \
    && apt-get install --no-install-recommends -y \
    build-essential \
    libpq-dev \
    libvips \
    curl \
    imagemagick \
    postgresql-client \
    nodejs \
    vim \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

compose.yml

name: "escrow_safe"
services:
  web:
    build:
      dockerfile: .devcontainer/Dockerfile
      context: ..
    ports:
      - "3000:3000"
      - "12345:12345"
    command: sleep infinity
    environment:
      - ES_DEV_PHONE_OVERRIDE
      - DEV_EMAIL_PREFIX=${USER}
      - DATABASE_URL=postgres://root:password@postgres-db/
      - EDITOR=vim
      - ES_DEBUG_ENABLED=true
    volumes:
      - ../..:/workspaces:cached
    depends_on:
      postgres-db:
        condition: service_healthy

  solidq:
    build:
      dockerfile: .devcontainer/Dockerfile
      context: ..
    command: bundle exec rails solid_queue:start
    environment:
      - DATABASE_URL=postgres-db://root:password@postgres-db/
    volumes:
      - ../..:/workspaces:cached
      # - bundler_gems:/usr/local/bundle
    depends_on:
      postgres-db:
        condition: service_healthy

  postgres-db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: password
    volumes:
      - db_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: pg_isready
      interval: 2s
      timeout: 5s
      retries: 30

volumes:
  db_data:

devcontainer.json

{
  "name": "escrow_safe",
  "dockerComposeFile": "compose.yaml",
  "service": "web",
  // "workspaceFolder": "/rails",
  "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
  // Features to add to the dev container. More info: https://containers.dev/features.
  "features": {
    "ghcr.io/devcontainers/features/github-cli:1": {},
    "ghcr.io/rails/devcontainer/features/activestorage": {},
    "ghcr.io/rails/devcontainer/features/postgres-client": {},
    "ghcr.io/rails/devcontainer/features/bundler-cache:1": {}
  },
  "containerEnv": {
    "CAPYBARA_SERVER_PORT": "45678",
    "SELENIUM_HOST": "selenium",
    "DB_HOST": "postgres"
  },
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  "forwardPorts": [
    3000,
    5432,
    6379
  ],
  // Configure tool-specific properties.
  // "customizations": {},
  // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
  // "remoteUser": "root",
  // Use 'postCreateCommand' to run commands after the container is created.
  "postCreateCommand": "bin/setup"
}
Share Improve this question asked Mar 19 at 17:04 James KleinJames Klein 6124 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Likely need something like (replace with valid path to the executables in this image)

ENV GEM_PATH="" \
    GEM_HOME="" \
    RUBY_HOME="" \
    PATH="/:${PATH}
发布评论

评论列表(0)

  1. 暂无评论