I have been trying to generate the “dbdocs” execution via docker but after resolving a lot of issues stuck finally at this point.
Here is the Dockerfile source -
# Use an official Node.js image as the base image
FROM node:14
# Set the working directory in the container
WORKDIR /app
# Install dbdocs globally using npm
RUN npm install -g dbdocs
# Expose the port used by dbdocs (default is 8080)
EXPOSE 10099
# Command to run dbdocs (customize as needed)
CMD ["dbdocs", "build", "--port", "10099", "login", "--github-token", "github-token-variable"]
Here is the source of docker-compose.yml -
my-dbdocs:
container_name: my-dbdocs
image: MYAWS.dkr.ecr.us-west-2.amazonaws.com/my-dbdocs:latest
ports:
- 10099:10099
environment:
- DBDOCS_DB_CONNECTION_STRING=mysql://root:root@my-mysql:3306/mydbdocsschema
- DBDOCS_DB_TYPE=mysql
- DBDOCS_API_PATH=/my-dbdocs
- DBDOCS_PORT=10099 # Customize the port for dbdocs
- DBDOCS_USERNAME=mydb-username
- DBDOCS_PASSWORD=mydb-password
-GITHUB_TOKEN=token-variable
After buliding the docker build while trying to run it, I’m getting this error.
docker-compose up my-dbdocs
Starting my-dbdocs ... done
Attaching to my-dbdocs
my-dbdocs | › Error: Please login first.
my-dbdocs exited with code 2
We have existing machine where few microservices already deployed as docker containers on the same machine I’m trying to add another docker image of dbdocs for schema documentation purpose.
It is marry go round process I have installed dbdocs via script
here is the script -
#!/bin/bash
# Check for root privileges
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
# Define the desired Node.js version
NODE_VERSION="14" # Change to your desired Node.js version (e.g., "14")
# Verify if Node.js is already installed
if ! command -v node &>/dev/null; then
echo "Node.js is not installed. Installing Node.js version $NODE_VERSION..."
# Add NodeSource repository for the specified Node.js version
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nodesource-archive-keyring.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/nodesource.list
# Update package list
apt update
# Install Node.js and npm
apt install -y nodejs
else
echo "Node.js is already installed."
fi
# Define the desired dbdocs version
DBDOCS_VERSION="0.8.1" # Change to your desired dbdocs version
# Verify if dbdocs is already installed
if ! npm list -g dbdocs@$DBDOCS_VERSION --depth=0 &>/dev/null; then
echo "dbdocs version $DBDOCS_VERSION is not installed. Installing..."
# Install dbdocs globally
npm install -g dbdocs@$DBDOCS_VERSION
else
echo "dbdocs version $DBDOCS_VERSION is already installed."
fi
# Verify installations
NODEJS_VERSION=$(node -v)
NPM_VERSION=$(npm -v)
DBDOCS_INSTALLED_VERSION=$(dbdocs --version)
echo "Node.js version: $NODEJS_VERSION"
echo "npm version: $NPM_VERSION"
echo "dbdocs version: $DBDOCS_INSTALLED_VERSION"
echo "Node.js, npm, and dbdocs have been installed successfully."
Now docs is up -
dbdocs
dbdocs ======
VERSION
dbdocs/0.8.1 linux-x64 node-v14.21.3
USAGE
$ dbdocs [COMMAND]
COMMANDS
build build docs
help Display help for dbdocs.
login login to dbdocs
logout logout
ls list projects
password set password for your project or remove password
remove remove project
rename change your username
token generate or revoke your authentication token
validate validate docs content
Now it is asking for login before generating the token -
dbdocs login
? Choose a login method: GitHub
? Please input your authentication token: <personal token from github>
✖ Validate token
› Error: Invalid token. Please login again.
Manually login and create your personal access token on your personal machine.
Add the access token as an environment variable in your docker container. Adding it will help your microservices run dbdocs CLI commands without authentication.
@Phuc_Nguyen@Thi_Nguyen Thanks for Login Instructions, here is the updated Dockerfile and docker-compose-file
# Use an official Node.js image as the base image
FROM node:14
# Set the working directory in the container
WORKDIR /app
# Install dbdocs globally using npm
RUN npm install -g dbdocs
# Expose the port used by dbdocs (default is 8080)
EXPOSE 10099
# Command to run dbdocs (customize as needed)
CMD ["dbdocs", "build"]
@Phuc_Nguyen Thanks, finally I have been able to run it one time but my sample db changes has been published here dbdocs.io - Database Documentation and Catalog Tool and after publishing it here docker container stopped immediately where as my expectation was that I will be able able to access it via https://localhost:10099, please let me know if I have missed anything here.
We don’t support self-hosted database documentation on localhost at the moment. the dbdocs CLI tool is only able to publish cloud-hosted documentation through our server.