目录

Deploying the ohpm-repo Service Using a Dockerfile

A Dockerfile, a text file used to build a Docker image, contains commands and instructions that enable the following operations:

Since ohpm-repo 5.4.3 Beta, you can use Docker commands to set up an ohpm-repo instance. This document describes how to implement this on Linux.

Environment setup

  1. Download the Docker image and set up the environment.
  2. Download the ohpm-repo tool package and rename the downloaded package to ohpm-repo.zip. (Click here to obtain the package.)
  3. Place the Dockerfile and ohpm-repo.zip in the same directory.
    The Dockerfile template is as follows:
    # Use the official Node.js 18 image.
    FROM node:18
    COPY ./ohpm-repo.zip /tmp/ohpm-repo.zip
    RUN mkdir -p /opt/ohpm-repo && \
        unzip /tmp/ohpm-repo.zip -d /opt/ohpm-repo && \
        rm -f /tmp/ohpm-repo.zip
    # Modify the listen configuration in conf/config.yaml. Do not use localhost or 127.0.0.1; instead, use 0.0.0.0.
    RUN if [ -f /opt/ohpm-repo/conf/config.yaml ]; then \
          sed -i 's/listen: [^ ]*/listen: 0.0.0.0:8088/g' /opt/ohpm-repo/conf/config.yaml; \
        fi
    ENV OHPM_REPO_BIN_DIR="/opt/ohpm-repo/bin"
    ENV PATH="${OHPM_REPO_BIN_DIR}:${PATH}"
    # Create a user. Do not run the ohpm-repo install and ohpm-repo start commands as the root user.
    RUN useradd -m myuser && \
        chown -R myuser:myuser /opt/ohpm-repo && \ 
        chmod -R 755 /opt/ohpm-repo
    USER myuser
    RUN ohpm-repo install
    ENV OHPM_REPO_DEPLOY_ROOT="/home/myuser/ohpm-repo"
    CMD ["ohpm-repo", "start"]

ohpm-repo service deployment

  1. Build an image in the directory containing the Dockerfile.
    docker build -t ohpm-repo .
  2. Start the service. You can run it in the foreground or the background.
    # Command to run it in the foreground
    docker run -it -p 8088:8088 ohpm-repo
    # Command to run it in the background
    docker run -d --restart=unless-stopped --name ohpm-repo -p 8088:8088 ohpm-repo
  3. Access the ohpm-repo service by visiting the IP address 8088 in a browser.