--- #https://www.notion.so/n8n/Frontmatter-432c2b8dff1f43d4b1c8d20075510fe4 contentType: tutorial --- # Docker Installation n8n recommends using [Docker](https://www.docker.com/) for most self-hosting needs. It provides a clean, isolated environment, avoids operating system and tooling incompatibilities, and makes database and environment management simpler. You can also use n8n in Docker with [Docker Compose](/hosting/installation/server-setups/docker-compose.md). You can find Docker Compose configurations for various architectures in the [n8n-hosting repository](https://github.com/n8n-io/n8n-hosting). --8<-- "_snippets/self-hosting/warning.md" ## Prerequisites Before proceeding, install Docker: * [Docker Desktop](https://docs.docker.com/get-docker/) is available for Mac, Windows, and Linux. Docker Desktop includes the Docker Engine and Docker Compose. * [Docker Engine](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/linux/) are also available as separate packages for Linux. Use this for Linux machines without a graphical environment or when you don't want the Docker Desktop UI. --8<-- "_snippets/self-hosting/installation/latest-next-version.md" ## Starting n8n From your terminal, run the following commands, replacing the `` placeholders with [your timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List): ```shell docker volume create n8n_data docker run -it --rm \ --name n8n \ -p 5678:5678 \ -e GENERIC_TIMEZONE="" \ -e TZ="" \ -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \ -e N8N_RUNNERS_ENABLED=true \ -v n8n_data:/home/node/.n8n \ docker.n8n.io/n8nio/n8n ``` This command creates a volume to store persistent data, downloads the required n8n image, and starts the container with the following settings: * Maps and exposes port `5678` on the host. * Sets the timezone for the container: * the `TZ` environment variable sets the system timezone to control what scripts and commands like `date` return. * the [`GENERIC_TIMEZONE` environment variable](/hosting/configuration/environment-variables/timezone-localization.md) sets the correct timezone for schedule-oriented nodes like the [Schedule Trigger node](/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/index.md). * Enforces secure file permissions for the n8n configuration file. * Enables [task runners](/hosting/configuration/task-runners.md), the recommended way of executing tasks in n8n. * Mounts the `n8n_data` volume to the `/home/node/.n8n` directory to persist your data across container restarts. Once running, you can access n8n by opening: [http://localhost:5678](http://localhost:5678) ## Using with PostgreSQL By default, n8n uses SQLite to save [credentials](/glossary.md#credential-n8n), past executions, and workflows. n8n also supports PostgreSQL, configurable using environment variables as detailed below. /// note | Persisting the `.n8n` directory still recommended When using PostgreSQL, n8n doesn't need to use the `.n8n` directory for the SQLite database file. However, the directory still contains other important data like encryption keys, instance logs, and source control feature assets. While you can work around some of these requirements, (for example, by setting the [`N8N_ENCRYPTION_KEY` environment variable](/hosting/configuration/environment-variables/deployment.md)), it's best to continue mapping a persistent volume for the directory to avoid potential issues. /// To use n8n with PostgreSQL, execute the following commands, replacing the placeholders (depicted within angled brackets, for example ``) with your actual values: ```shell docker volume create n8n_data docker run -it --rm \ --name n8n \ -p 5678:5678 \ -e GENERIC_TIMEZONE="" \ -e TZ="" \ -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \ -e N8N_RUNNERS_ENABLED=true \ -e DB_TYPE=postgresdb \ -e DB_POSTGRESDB_DATABASE= \ -e DB_POSTGRESDB_HOST= \ -e DB_POSTGRESDB_PORT= \ -e DB_POSTGRESDB_USER= \ -e DB_POSTGRESDB_SCHEMA= \ -e DB_POSTGRESDB_PASSWORD= \ -v n8n_data:/home/node/.n8n \ docker.n8n.io/n8nio/n8n ``` You can find a complete `docker-compose` file for PostgreSQL in the [n8n hosting repository](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgres). ## Updating To update n8n, in Docker Desktop, navigate to the **Images** tab and select **Pull** from the context menu to download the latest n8n image: ![Docker Desktop](/_images/hosting/installation/docker/docker_desktop.png) You can also use the command line to pull the latest, or a specific version: ```shell # Pull latest (stable) version docker pull docker.n8n.io/n8nio/n8n # Pull specific version docker pull docker.n8n.io/n8nio/n8n:1.81.0 # Pull next (unstable) version docker pull docker.n8n.io/n8nio/n8n:next ``` After pulling the updated image, stop your n8n container and start it again. You can also use the command line. Replace `` in the commands below with the container ID you find in the first command: ```shell # Find your container ID docker ps -a # Stop the container with the `` docker stop # Remove the container with the `` docker rm # Start the container docker run --name= [options] -d docker.n8n.io/n8nio/n8n ``` ### Updating Docker Compose --8<-- "_snippets/self-hosting/installation/docker-compose-updating.md" --8<-- "_snippets/self-hosting/installation/tunnel.md" Start n8n with `--tunnel` by running: ```shell docker volume create n8n_data docker run -it --rm \ --name n8n \ -p 5678:5678 \ -e GENERIC_TIMEZONE="" \ -e TZ="" \ -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \ -e N8N_RUNNERS_ENABLED=true \ -v n8n_data:/home/node/.n8n \ docker.n8n.io/n8nio/n8n \ start --tunnel ``` ## Next steps * Find more information about Docker setup in the README file for the [Docker image](https://github.com/n8n-io/n8n/tree/master/docker/images/n8n). --8<-- "_snippets/self-hosting/installation/server-setups-next-steps.md"