Overview of Docker in Development
Docker is utilized within the OpenTelemetry development environment to facilitate consistent application behavior across different stages of development and to streamline the setup process. This page provides a step-by-step guide on how to configure and use Docker for this purpose.
Prerequisites
Ensure Docker is installed and running on your development machine. Check installation by running:
docker --version
Dockerfile Configuration
In the OpenTelemetry repository, a Dockerfile defines the environment in which the application will run. A standard Dockerfile setup may look like the following:
# Use an official Node runtime as a parent image
FROM node:14-alpine
# Set the working directory
WORKDIR /usr/src/app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application’s source code
COPY . .
# Expose the port the app runs on
EXPOSE 8080
# Define the command to run the app
CMD ["npm", "start"]
This Dockerfile builds a container with Node.js and prepares the OpenTelemetry application for development.
Docker Compose
To simplify the management of multi-container applications, Docker Compose can be utilized. A docker-compose.yml
file for the OpenTelemetry project could resemble the following:
version: '3.8'
services:
opentelemetry:
build: .
ports:
- "8080:8080"
volumes:
- .:/usr/src/app
environment:
NODE_ENV: development
With this docker-compose.yml
, you can build and run the OpenTelemetry application using:
docker-compose up
This command initiates the build process specified in the Dockerfile, runs the application, and maps the local port to the container.
Makefile Functions
The OpenTelemetry project leverages a Makefile to encapsulate common command-line tasks that are useful during development. Here are some key functions available:
default
This function is the default target and can be invoked with:
make
ls-public
Lists public resources in the documentation directory:
make ls-public
check-links
Run this function to check the links present in the documentation:
make check-links
public
Builds the public version of the documentation:
make public
By combining the power of Docker and the Makefile, developers can maintain an efficient and organized workflow.
Running Tests
To run tests within the Docker environment, you can include a test section in the Dockerfile. Below is an example of how to modify the existing Dockerfile for testing purposes:
# Install test dependencies
RUN npm install --only=dev
# Command to run tests
CMD ["npm", "test"]
To execute the tests using Docker Compose, run:
docker-compose run opentelemetry
This command initiates a new container specifically for running tests and ensures that the development environment remains unaffected.
Conclusion
Utilizing Docker in the OpenTelemetry development environment ensures that the setup is repeatable, consistent, and isolated from the local system’s configuration. Coupling Docker with Makefile functions facilitates efficient task management, aiding expert developers in maintaining robust workflows.
Source: OpenTelemetry Makefile
(distance: 0)