NetrunHome

How to publish a project with a database

· 5 min read

While the project lives on your computer, putting a database next to it takes one command. As soon as it comes to publishing, a separate story begins: where the database will live, how the app connects to it, where to keep the password, what happens to the data on the next code update. The classic path is to rent a server, install the database on it, set up access and remember about backups.

An app with a database can be moved out as a whole, as one project. Netrun brings up connected services from a docker-compose file: the app and the database side by side, up to five services per project. The data lives in permanent storage and survives code updates. Here is how to put it together.

  1. Describe the app and the database in one file

    Put a docker-compose.yml in the project root and describe two services in it: your app and a database — PostgreSQL, MySQL, MongoDB or Redis, from a ready-made official image. We build the app from your code, and the database comes from the image: there is nothing to install or configure by hand.

  2. Give the database permanent storage

    This is the key step you must not skip. Add a named volume to the database and attach it to the folder where the database keeps its files. Without a volume the data sits inside the container and is wiped on the very first code update. With a volume it survives restarts and republishing — we only remove such data when you delete the project yourself.

  3. Connect services by name, not by address

    Inside a project, services see each other by the names from the description file. If the database is called db, the app connects to the host db on the database default port — there is no need to write IP addresses, and you should not: they change on restart. The database is not exposed to the outside: only the app gets a public address, while the database is reachable only from the neighbouring service.

  4. Move the database password into secrets

    Do not write the database password, user name and connection string into the description file or leave them in the code — read them from environment variables. During project setup Netrun asks for these values and puts them into the environment encrypted, so the password never sits in the archive or the repository.

  5. Upload the project and apply the schema

    Upload the folder as a ZIP archive or import a repository from GitHub. Netrun sees the service description, brings up the database and the app and issues a public HTTPS address. Leave table creation to the app itself — migrations on startup or your framework’s built-in mechanism. Then the schema appears on the first run, and on later updates the data stays in place.

The result: the app and the database live as one project, the connection is configured, the password sits in secrets, and the data does not disappear on code updates. No server, no manual database installation and no access configuration were needed. Try Netrun.

Common questions

Will my data disappear on a code update?

No, if the database has a named volume attached. Then a code update only rebuilds the app, while the database files stay in place. Without a volume the data sits inside the container and is wiped on the first republish, so this step is mandatory.

Which databases can I run?

Any that ship a ready-made image: PostgreSQL, MySQL, MariaDB, MongoDB, Redis and others. It is enough to describe the service in the docker-compose file — there is nothing to install or configure by hand.

How does the app connect to the database?

By the service name from the description file. If the database is called db, the connection string points at the host db and the database default port. There is no need for IP addresses: they change on restart, while the name stays the same.

Will the database be reachable from the internet?

No. Only the app gets a public address, while the database is visible only to neighbouring services inside the project. That is the right behaviour: a database exposed to the outside is the most common way to lose data.

How many services fit in one project?

Up to five. That is usually enough: an app, a database, a cache and, say, a background job worker.

Can I run several services at once?

Yes. With docker-compose you can bring up to five connected services in one project — for example, an app together with a database.

Is my data kept when I update the code?

Yes. Your database and project files survive a code update and a restart, and the project link stays the same too.

Where do I set tokens and other secret values?

In the project settings there is a section for values from your code — for example, the token from BotFather. We store them encrypted.