Skip to content

feat: customize port number #5393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

syrius527
Copy link

@syrius527 syrius527 commented Mar 22, 2025

Hi, I am a back-end developer at a Korean startup. While deploying an application web server as a Docker container on a self-hosted Ubuntu server, I integrated Coolify for its CI/CD. However, I found it inconvenient that the port for Coolify was fixed at 8000. Since this is my first contribution, it might not be perfect, but I wanted to improve this aspect and suggest a feature to customize the port when installing Coolify on self hosted servers.

Submit Checklist (REMOVE THIS SECTION BEFORE SUBMITTING)

  • I have selected the next branch as the destination for my PR, not main.
  • I have listed all changes in the Changes section.
  • I have filled out the Issues section with the issue/discussion link(s) (if applicable).
  • I have tested my changes.
  • I have considered backwards compatibility.
  • I have removed this checklist and any unused sections.

Changes

This PR adds support for specifying a custom port number when installing Coolify on a self-hosted server. The following changes have been made:

  • Modified the installation script (install.sh) to allow specifying a custom port using the --port (-p) option instead of the default 8000 if needed.
  • Updated .env.production file generation to include the APP_PORT key, so that .env file's APP_PORT can have the provided custom port number or falling back to 8000 if not specified.
  • Modified upgrade.sh to reference the APP_PORT value from the .env file, ensuring that the Coolify Docker container runs on the specified port.
  • Updated the documentation to guide users on installing Coolify with a custom port using:
    curl -fsSL https://cdn.coollabs.io/coolify/install.sh | sudo bash -s -- --port {{PORT_NUM}}

Let me know if there's anything that needs improvement!

Issues

  • fix #

@djsisson
Copy link
Contributor

fyi you can also do this by creating this file here /data/coolify/source/docker-compose.custom.yml

with the contents:

services:
  coolify:
    ports: !override
      - "1234:8080" 

this is useful if you need to remove ports altogether if on cloudflared etc, you can just use ports: !reset []

@andrasbacsai
Copy link
Member

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Enabled custom port configuration during installation and upgrade, allowing users to specify a port number other than the default.
    • Updated application messages to reflect the dynamically set port during runtime.
  • Documentation

    • Enhanced setup instructions with guidelines on how to use the new option for specifying a custom port.

Walkthrough

Listen up, meatbags. The update introduces a new environment variable, APP_PORT, into the production environment file, positioning it between APP_KEY and DB_USERNAME without disturbing the existing order. The README now explains how to customize the port for the Coolify application using a new --port option. Meanwhile, the installation script (scripts/install.sh) now accepts custom port parameters (-p or --port), validating inputs and updating generated .env files and output messages accordingly. The upgrade script (scripts/upgrade.sh) retrieves the new port setting from the environment file, defaulting to 8000 if not specified. Now, get out there and enjoy these changes—preferably with a taco in hand.

Changes

File(s) Change Summary
.env.production Added APP_PORT between APP_KEY and DB_USERNAME without modifying existing variables.
README.md Updated installation instructions to include a --port option for customizing the application port instead of using the default 8000.
scripts/install.sh Introduced a new PORT variable with default value 8000, added -p/--port options for custom port input, validated numeric input, and modified the generation of the .env file to include APP_PORT. Also updated output messages with the dynamic port value.
scripts/upgrade.sh Added logic to retrieve APP_PORT from the /data/coolify/source/ .env file, setting PORT to its value or defaulting to 8000 if not set, before running configuration downloads.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant I as install.sh
    participant ENV as .env Generator
    participant Msg as Output Messages

    U->>I: Invoke install.sh [-p PORT]
    I->>I: Parse options (-p/--port) and validate input
    alt Valid Port Specified?
      I->>I: Set PORT to provided value
    else
      I->>I: Default PORT to 8000
    end
    I->>ENV: Generate .env file with APP_PORT
    ENV-->>I: .env file created
    I->>Msg: Update output messages with dynamic PORT
    Msg-->>U: Display updated access URLs
Loading
sequenceDiagram
    participant U as User
    participant UPG as upgrade.sh
    participant ENV as .env Reader

    U->>UPG: Invoke upgrade.sh
    UPG->>ENV: Read APP_PORT from /data/coolify/source/.env
    alt APP_PORT exists?
      ENV-->>UPG: Return APP_PORT value
    else
      UPG->>UPG: Default PORT to 8000
    end
    UPG->>U: Proceed with configuration downloads using PORT
Loading
✨ Finishing Touches
  • 🔥 Error while generating docstrings. (🔄 Check again to generate again)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7d80e9 and b34cbad.

📒 Files selected for processing (4)
  • .env.production (1 hunks)
  • README.md (1 hunks)
  • scripts/install.sh (5 hunks)
  • scripts/upgrade.sh (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

24-24: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)


26-26: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)

🔇 Additional comments (6)
scripts/upgrade.sh (1)

12-15: Dynamic Port Retrieval – No more guessing, only facts!
The upgrade script now correctly extracts APP_PORT from the environment file and defaults to 8000 when not set. This straightforward approach ensures your Docker container isn’t left hanging with a mysterious port. Good work, soldier.

scripts/install.sh (5)

24-24: Default Port Initialization – Setting your aim for 8000!
Initializing PORT=8000 as the default is a solid start. This ensures the server won’t misfire when no custom port is provided. Keep it simple, just like a well-balanced taco.


48-52: Numeric Port Validation – No rogue letters allowed!
The regex check ensuring that $PORT contains only digits is on point. This guards against non-numeric inputs that could crash your server faster than a half-eaten taco.


54-58: Customized Greeting – Shouting out your custom port clearly!
The conditional message distinguishing between the default port and a user-defined port is clear and informative. Now, your users will know exactly where to hit up Coolify—whether they like plain 8000 or something spicier.


717-721: Environment File Update – Propagating that port like hot salsa!
The sed command updating the APP_PORT in the backup .env file ensures that your custom port setting rides along with the rest of the configuration. This is a neat and secure way to propagate your new port choice.


826-837: Dynamic Access URL Display – Your server now talks with clarity!
The echo commands updating the public and private access URLs to include the custom port are on target. Users will see the correct port in the access message, ensuring they don’t end up on a ghost port. Tacos and servers alike appreciate clarity.

Comment on lines 1 to +4
APP_ID=
APP_NAME=Coolify
APP_KEY=
APP_PORT=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

APP_PORT Variable Addition – Hasta la vista, hardcoding!
The new APP_PORT= entry is correctly positioned between APP_KEY and DB_USERNAME. Since the installation script provides a default of 8000 if left empty, this placeholder is acceptable. Just make sure to document that empty means “default port 8000” for clarity.

Comment on lines +23 to +26
If you want to customize the port for running Coolify, which is 8000 by default, you can specify it with the following command:
```bash
curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash -s -- --port {{PORT_NUMBER}}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Enhanced Documentation – Tacos and ports for everyone!
The README now clearly explains how to install Coolify with a custom port using the --port option. However, markdownlint warning MD031 suggests surrounding fenced code blocks with blank lines—adding these extra newlines would keep your documentation as neat as a well-organized taco truck.

Proposed diff:

-If you want to customize the port for running Coolify, which is 8000 by default, you can specify it with the following command:
-```bash
-25~
-curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash -s -- --port {{PORT_NUMBER}}
-26~
-```
+If you want to customize the port for running Coolify, which is 8000 by default, you can specify it with the following command:
+
+```bash
+curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash -s -- --port {{PORT_NUMBER}}
+```
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

24-24: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)


26-26: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)

Comment on lines +35 to +46
while getopts "p:-:" opt; do
case "$opt" in
p) PORT="$OPTARG" ;;
-)
case "$OPTARG" in
port) PORT="${!OPTIND}"; OPTIND=$((OPTIND + 1)) ;;
*) echo "Invalid option: --$OPTARG" >&2; exit 1 ;;
esac
;;
?) echo "Usage: $0 [-p port] [--port port]" >&2; exit 1 ;;
esac
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Robust Getopts Parsing – Making your port command-line friendly!
The new getopts loop to support -p and --port is working hard for you. It cleanly assigns the custom port value. Consider quoting variables like "${OPTARG}" for extra safety, but overall it’s a killer move.

@coollabsio coollabsio deleted a comment from coderabbitai bot Mar 25, 2025
@peaklabs-dev peaklabs-dev added the 🛠️ Feature Issues requesting a new feature. label Mar 31, 2025
@colinmollenhour
Copy link

colinmollenhour commented Apr 8, 2025

I was kinda surprised to find that so many ports were open - given that it sets up Traefik proxy, why does port 6001, 6002, 8000 and 8080 have to be exposed at all? The containers communicate on the Docker network so is there any reason for these to be exposed?

I disabled them and haven't noticed any issues so far:

`/data/coolify/source/docker-compose.custom.yml':

services:
  coolify:
    ports: !reset []
    expose: !reset []
  soketi:
    ports: !reset []

(thanks @djsisson for hint on how to reset!)

/data/coolify/proxy/docker-compose.yml:

Comment out port 8080:

    ports:
      - '80:80'
      - '443:443'
      - '443:443/udp'
#      - '8080:8080'

@andrasbacsai andrasbacsai deleted the branch coollabsio:next May 9, 2025 06:31
@andrasbacsai
Copy link
Member

It was a mistake, sorry. I recreated the next branch and it auto-closed this PR.

@andrasbacsai andrasbacsai reopened this May 9, 2025
@Cinzya
Copy link

Cinzya commented May 17, 2025

@colinmollenhour these ports are there for cases when the Traefik proxy might go down, so people can continue to access Coolify and use all its features easily. Port 8000 is being used by the Coolify Dashboard and 6001 + 6002 are then needed for communication with the realtime service via websocket connections. (I can't remember from the top of my head what 8080 was for again).

@djsisson
Copy link
Contributor

djsisson commented May 17, 2025

@Cinzya 8080 is for traefik dashboard

all 3 ports are only required when the proxy is down (6001, 6002, 8000) so having them open all the time is not required

if the proxy goes down, you can always manually restart it, so outside of inital installation imo, they can be closed

a different solution would be to have a bootstrap nginx in the compose, which you can start/stop to open close those ports during installation / no proxy / restoration etc

i.e if coolify detects the proxy is not running, it would start the nginx container so be accessible on 8000, then when proxy is running it owuld stop it again, thus minimizing the amount of open ports

the reason for wanting to close them is, it is very easy to restrict access to domains externally using say cloudflare or traefik failtoban plugins. but you can't when there is a direct connection to the container always open.

@colinmollenhour
Copy link

Opening ports unnecessarily is bad security practice. If anything, they could just be opened on the localhost:

    ports:
      - '80:80'
      - '443:443'
      - '443:443/udp'
      - '127.0.0.1:8080:8080'

This way you can easily access it from within a remote SSH session or using a temporary http tunnel like ngrok, but it's not exposed to the public 24/7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ Feature Issues requesting a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants