crontab is installed in all containers built with the offly image. You can use it to automate any bash scripts or commands and have it run 24/7.
# Use this to edit the cron file crontab -e
To learn how to write crontab schedules, click here.
You can run any Node.js web server in an offly docker container just like on your computer.
First, inside the container, install a server software like express using NPM:
npm install express
Then you can write any server code in a .js file and run it:
// server.js
const app = require("express")();
app.get("/", function(req, res) {
res.send("Hello world!");
});
app.listen(8080);
node server.js
To visit a server running inside your container or use it as an API, use https://offly.pagekite.me/containers/API_KEY/CONTAINER_NAME/PORT, replacing with actual values as needed.
Tip: If you run any server or forever-running command from your Container Dashboard, then close the browser/tab, the command will keep running in the background of your container. Any output will go to your logs. This is convenient for running web servers just like Node.js!
This is just a quick way to run a python web server using Python, but you can write any Python server you want - this is just an example:
# Starts a file server on port 3000 python3 -m http.server
Yes, that's right! You can use the node-offly Node.js module and automate offly containers or other APIs using Node.js.
npm install node-offly
// Example for updating a file
// inside your offly container
// on a schedule
const offly = require("node-offly");
offly.init("XXX");
setInterval(function() {
offly.execCommand("MyAwesomeContainer", "echo $(date) > current_date.txt");
}, 24 * 60 * 60 * 1000); // Once a day
node script.js
If you built a container using the nginx:alpine image, all you need to do is start the container and the server will run automatically.
To add more pages or edit them, all webpages/files for the server will be located in /usr/share/nginx/html.