Base Images
When multiple components share common dependencies, you can create a base image to avoid duplication.
The Problem
Section titled “The Problem”Imagine you have several Node.js services that all need:
- The same Node.js version
- Common system packages (like
curlfor health checks) - Shared utility libraries
Without a base image, you’d duplicate this setup in every Dockerfile.
The Solution: Base Component
Section titled “The Solution: Base Component”Our microservices example has a base component:
cat base/DockerfileFROM node:22-alpine
# Install common dependenciesRUN apk add --no-cache curl
WORKDIR /app
# Copy shared utilitiesCOPY utils.js ./
# Set default environmentENV NODE_ENV=developmentThis creates a foundation image with:
- Node.js 22 on Alpine Linux
- curl installed for health checks
- A shared
utils.jsmodule - Common environment setup
The Base Embfile
Section titled “The Base Embfile”The base component’s configuration:
cat base/Embfile.ymldescription: Shared base image with common dependencies
tasks: info: description: Show base image info script: echo "Base image provides shared Node.js utilities" # Restrict this task to run only on the local machine (not inside a container). # By default, tasks can run on multiple executors (local, container). # Setting 'executors: [local]' means: # - The task runs on your host machine only # - Attempting to run with --executor=container will fail # - Useful for tasks that need host-level access or don't make sense in a container executors: - localUsing the Base Image
Section titled “Using the Base Image”Other components inherit from this base. Here’s the worker’s Dockerfile:
cat worker/DockerfileARG DOCKER_TAG=latestFROM microservices/base:${DOCKER_TAG}
WORKDIR /app
COPY package.json ./RUN npm install --production
COPY worker.js ./
CMD ["node", "worker.js"]Notice FROM microservices/base:${DOCKER_TAG} - it inherits from our base image, using a build argument for the tag.
Benefits
Section titled “Benefits”- Consistency - All services use the same Node.js version and utilities
- Faster builds - Common layers are cached in the base image
- Single update point - Update the base, rebuild dependents
Next Step
Section titled “Next Step”Continue to Dependencies to see how EMB tracks these relationships.