Anybody know how to properly expose a commandbox s...
# box-products
j
Anybody know how to properly expose a commandbox server running inside a docker container? Hoping to hit it from a web browser outside the container but I'm getting ERR_EMPTY_RESPONSE, whereas inside the container I can curl it just fine. More specifically, I am running a Lucee container for my main app and using commandbox at this time for testbox. I have the port mapped correctly (42518:42518). My (8080:80) port mapping for the main application works fine. I tried setting host of the commandbox server to 0.0.0.0, which of course DOES expose it outside the container (via localhost:42518) but all I see is "Forbidden" on the page.
b
@Jason Ryan What image are you using?
ortussolutions/commandbox
?
What server profile is in use and what URL are you hitting?
What is the console output of the container showing?
Have you tried doing a debug start for more info in the console?
Also, what does the forbidden page look like? I need to know where it's coming from. Undertow, your code, etc
j
Using the standard lucee docker image, not commandbox (we'd like to move to that at some point)
Here's the forbidden page
b
Hmm, is that an
<h1>
?
j
Here is hte output log of how I'm starting it
Not H1, just straight in the body
b
Hmm, not undertow
I'm confused how your starting it though, what image is this?
The ortus image does the start for you
j
Inside the
lucee:5.3.10.120-light-nginx
image I have this step to install commandbox
So I just exec into the main container and run
box start
b
That's super confusing, lol
Why are you using the Lucee image and installing commandbox and starting a server?
That's breaking like 17 rules all at once, lol
Let's back up-- what is your overall goal right now?
j
Yeah, it doesn't seem ideal. Commandbox was added after the fact for migrations, cfconfig, and now testbox. We should totally backup and only use commandbox right?
Overall goal right now is to run tests
b
If you just want to start a server, you can use
ortussolutions/commandbox
and map your code into
/app
but a lot of this depends on what your expectations are and how your app is set up.
j
Ok yeah that's not a bad idea, I can just spin up another container for the tests
b
The CommandBox docker image expects you to use
server.json
and a specific set of env vars to configure it (CFConfig too)
If your company has some existing investment into the Lucee docker container for ... reasons, that doesn't necessarily work the same
Now, generally speaking, I recommend using the commandbox image for everything. It's far superior in a number of ways, but I'm fairly biased 🙂
There's not really anything the Lucee image does that the ortus one doesn't, but the ortus image defo does a ton that the Lucee image doesn't do
j
Yeah, every time I look at the docs it amazes me how much more you can do with the commandbox image
b
But I don't know what your constraints are-- if your coworkers already decided they wanted to use the Lucee image instead for some reason then a convo of switching base images may be out of the question
j
Yeah that's not the case, its almost tech debt at this point being on the Lucee image, dev time is the constraint
b
Now as far as running tests-- that's another can of worms. That can mean different things. Are you intending to use the CLI
testbox run
command, or do you just want to hit them in the browser, etc, etc?
If you already have your app up and running in the Lucee container, then just hitting the test URL will run the tests!
So I'm not sure where you wound up off in the weeds trying to start a second server in the container 🙂
And furthermore, are you wanting to run the tests inside the container, or outside?
j
Yes I have success with using the
testbox run
command in the CLI, we use that in our CI/CD for example. The reason I wanted to hit it in the browser is for better debugging capabilities, as in seeing my output (I posted about this earlier and someone recommended to hit it in the browser)
b
Which boils down to how you are trying to consume them. A browser, a
curl
command,
testbox run
, etc
Right, so the
testbox run
command shows you the URL it hits. You can just copy that and use whatever the existing ports are that are mapped outside of your container
Take off the
reporter=JSON
bit and you'll get an HTML version
j
I guess I was looking to do both? I like the CLI for just seeing overall response of the test and for the watch capbiliy. But if I'm digging into an issue with on of the tests I want to output things and see them so the browser seems ideal for that
I might have to try that, just using my existing Lucee app. I will have to move the testbox folder inside my webroot though, thats the only thing
Yeah it's when I hit the
testbox run
URL that I get ERR_EMPTY_RESPONSE, despite having port
42518
mapped outside the container
b
If you're just playing with the tests, I would just run the locally. And I don't use docker for local dev. Just a good old CommandBox server
Your testbox run depends on whether your running that commmand INSIDE the container or outside. There's too much I don't know about your container setup to comment on the ports.
but I presume you're able to access the actual app that's running somehow in a browser?
The testbox runner is normally just a sub folder off that
j
Yeah I can access the actual app no problem
Didn't think of just running commandbox outside of docker, that's not a bad idea ta all
b
so add
/tests/runner.cfm
to the end 🙂
j
The testbox runner sits just outside the webroot that my actual app serves, so yeah I'd have to modify its location to hit it in the url like that
b
Well, if this is local, I'd ditch docker entirely,
j
Yup its local
b
but generally speaking, there's no particular reason to run the testbox run inside the container if the container is only there to start the site up
j
I had it setup that way for better portability amongst the devs, one less dependency to install themselves haha
b
CommandBox is designed to be a general purpose CF developer tool that you install directly on your PC and if you point the
testbox run
command at a URL that happens to be hosted on a docker container, the CLI doesn't even care
better portability
Right, you'll find I'm fairly opinionated about this and feel free to discard my opinions, but my take is that CommandBox itself offers 98% of the portability you need with MUCH LESS hassle than Docker which is a HUGE dependency, both size, resource, and knowledge-wise
j
That's great to know. You've given me multiple ways to go about this 🙂
I appreciate your opinions! I'll probably take your word for it and give that a shot
b
With CommandBox alone, which just requires a
box.exe
to be dropped on the desktop, a new develpepr workflow is literally just
Copy code
git clone ...
box install
box start
And that's it-- forget the whole complicated docker layer!
j
You gotta add it to your path in windows tho right?
b
You've already got the server auto-installed by a binary that works the same on Mac, Linux, and Windows
No
I mean, you can if you want to run
box
commands anywhere
but you can also just double click the stupid EXE and you're off
j
Haha fair enough
b
IN fact, you can run the git command from INSIDE the interactive shell 🙂
Copy code
<double click box.exe>
cd /path/to/projects
!git clone ...
cd project
install
server start
Lots of ways to do it, but CommandBox becomes your entire web server and servlet container
j
Did not know you can run git in there. That's awesome. Commandbox is legit
b
you can run any native binary with
!
in front
I use CommandBox as my normal every-day shell in Windows
I leave a dedicated instance open all day
The one place I do think docker compose can come in handy is if you have a more complicated app that needs to spin up • local DB • redis cache • some oddball hard requirements on Nginx, or Apache, etc
Then there can be some benifit, but for any standalone server that connects to a DB over a VPN my
box install
and
box start
can already encapulate • CF engine • Java version • jvm args • web server settings • CFConfig • dependencies
j
Yeah I can see that. We do use docker compose to run 2 services, lucee and postgres
👍 1
b
Heck, CommandBox servers even let your force case sensitivity to be on or off so Windows and Linux devs have the same experience
j
I'm definitely inspired to use commandbox more 😄
Appreicate your input, I think I have what I need to get this running tomorrow
🙂 1
b
Here's this if you have some reading time https://commandbox.ortusbooks.com/