# Instalação e configurações N8N

Instalação e configurações N8N

# Instalação N8N docker (1)

Link: [https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#5-create-docker-compose-file](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#5-create-docker-compose-file)

If you have already installed Docker and Docker-Compose, then you can start with step 4.

Self-hosting knowledge prerequisites

Self-hosting n8n requires technical knowledge, including:

<div class="admonition note" id="bkmrk-setting-up-and-confi" style="text-align: justify;">- Setting up and configuring servers and containers
- Managing application resources and scaling
- Securing servers and applications
- Configuring n8n

</div>n8n recommends self-hosting for expert users. Mistakes can lead to data loss, security issues, and downtime. If you aren't experienced at managing servers, n8n recommends [n8n Cloud](https://n8n.io/cloud/).

Latest and Next versions

n8n releases a new minor version most weeks. The `latest` version is for production use. `next` is the most recent release. You should treat `next` as a beta: it may be unstable. To report issues, use the [forum](https://community.n8n.io/c/questions/12).

Current `latest`: 1.58.2  
Current `next`: 1.59.0

### 1. Install Docker[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#1-install-docker "Permanent link")

This can vary depending on the Linux distribution used. You can find detailed instructions in the [Docker documentation](https://docs.docker.com/engine/install/). The following example is for Ubuntu:

```
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
```

### 2. Optional: Non-root user access[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#2-optional-non-root-user-access "Permanent link")

Run when logged in as the user that should also be allowed to run docker:

```
sudo usermod -aG docker ${USER}
su - ${USER}
```

### 3. Install Docker-Compose[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#3-install-docker-compose "Permanent link")

This can vary depending on the Linux distribution used. You can find detailed instructions in the [Docker documentation](https://docs.docker.com/compose/).

The example below is for Ubuntu:

```
sudo apt-get install docker-compose-plugin
```

### 4. DNS setup[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#4-dns-setup "Permanent link")

Add A record to route the subdomain accordingly:

```
Type: A
Name: n8n (or the desired subdomain)
IP address: <IP_OF_YOUR_SERVER>
```

### 5. Create Docker Compose file[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#5-create-docker-compose-file "Permanent link")

Create a `docker-compose.yml` file. Paste the following in the file:

```
version: "3.7"

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - traefik_data:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  traefik_data:
    external: true
  n8n_data:
    external: true
```

If you are planning on reading/writing local files with n8n (for example, by using the [Read/Write Files from Disk node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.filesreadwrite/), you will need to configure a data directory for those files here. If you are running n8n as a root user, add this under `volumes` for the n8n service:

```
- /local-files:/files
```

If you are running n8n as a non-root user, add this under `volumes` for the n8n service:

```
- /home/<YOUR USERNAME>/n8n-local-files:/files
```

You will now be able to write files to the `/files` directory in n8n and they will appear on your server in either `/local-files` or `/home/<YOUR USERNAME>/n8n-local-files`, respectively.

### 6. Create `.env` file[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#6-create-env-file "Permanent link")

Create an `.env` file and change it accordingly.

```
# The top level domain to serve from
DOMAIN_NAME=example.com

# The subdomain to serve from
SUBDOMAIN=n8n

# DOMAIN_NAME and SUBDOMAIN combined decide where n8n will be reachable from
# above example would result in: https://n8n.example.com

# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=Europe/Berlin

# The email address to use for the SSL certificate creation
SSL_EMAIL=user@example.com
```

### 7. Create data folder[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#7-create-data-folder "Permanent link")

Create the Docker volume that's defined as `n8n_data`. n8n will save the database file from SQLite and the encryption key in this volume.

```
sudo docker volume create n8n_data
```

Create a volume for the Traefik data, This is defined as `traefik_data`.

```
sudo docker volume create traefik_data
```

### 8. Start Docker Compose[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#8-start-docker-compose "Permanent link")

n8n can now be started via:

```
sudo docker compose up -d
```

To stop the container:

```
sudo docker compose stop
```

### 9. Done[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#9-done "Permanent link")

n8n will now be reachable using the above defined subdomain + domain combination. The above example would result in: `https://n8n.example.com`

n8n will only be reachable using `https` and not using `http`.

Secure your n8n instance

Make sure that you [set up authentication](https://docs.n8n.io/hosting/user-management/) for your n8n instance.

## Next steps[\#](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/#next-steps "Permanent link")

- Learn more about [configuring](https://docs.n8n.io/hosting/configuration/environment-variables/) and [scaling](https://docs.n8n.io/hosting/scaling/overview) n8n.
- Or explore using n8n: try the [Quickstarts](https://docs.n8n.io/try-it-out/).

# Instalação N8N docker com worker

Link: [https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose)

git clone [https://github.com/n8n-io/n8n-hosting.git](https://github.com/n8n-io/n8n-hosting.git)

Download: [https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgresAndWorker](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgresAndWorker)

<div data-hpc="true" id="bkmrk-name-last-commit-mes" style="text-align: justify;"><table aria-labelledby="folders-and-files" class="Table-module__Box--h4W6R DirectoryContent-module__Table--DNJx9" style="width: 107.737%;"><thead class="Table-module__Box_1--JrPYF"><tr class="Table-module__Box_2--kJgvd"><th class="DirectoryContent-module__Box_1--mB8B7" colspan="1" style="width: 35.0287%;"><span class="text-bold">Name</span></th><th class="hide-sm" style="width: 44.1132%;"><div class="Truncate__StyledTruncate-sc-23o1d2-0 liVpTx width-fit" title="Last commit message"><span class="text-bold">Last commit message</span></div></th><th class="DirectoryContent-module__Box_2--LsXd4" colspan="1" style="width: 20.8582%;"><div class="Truncate__StyledTruncate-sc-23o1d2-0 liVpTx width-fit" title="Last commit date"><span class="text-bold">Last commit date</span></div></th></tr></thead><tbody><tr class="Table-module__Box_3--SP5mx" id="bkmrk-parent-directory-.."><td class="f5 text-normal px-3" colspan="3" style="width: 100%;">### parent directory

[<div class="width-full DirectoryRow-module__Box--NOziH"><svg aria-hidden="true" class="octicon octicon-file-directory-fill Octicon-sc-9kayk9-0 DirectoryRow-module__Octicon--S5rCK" display="inline-block" fill="currentColor" focusable="false" height="16" overflow="visible" viewbox="0 0 16 16" width="16"><path d="M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"></path></svg>..</div>](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose)</td></tr><tr class="react-directory-row undefined" id="bkmrk-.env-add-encryption-"><td class="react-directory-row-name-cell-large-screen" colspan="1" style="width: 35.0287%;"><div class="react-directory-filename-column"><svg aria-hidden="true" class="octicon octicon-file color-fg-muted" display="inline-block" fill="currentColor" focusable="false" height="16" overflow="visible" viewbox="0 0 16 16" width="16"><path d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg><div class="overflow-hidden"><div class="react-directory-filename-cell"><div class="react-directory-truncate">[.env](https://github.com/n8n-io/n8n-hosting/blob/main/docker-compose/withPostgresAndWorker/.env ".env")</div></div></div></div></td><td class="react-directory-row-commit-cell" style="width: 44.1132%;"><div><div class="react-directory-commit-message">[add encryption key env variable](https://github.com/n8n-io/n8n-hosting/commit/a2e303b611ad00071588b43331fed96276c62834 "add encryption key env variable")</div></div></td><td style="width: 20.8582%;"><div class="react-directory-commit-age">8 months ago</div></td></tr><tr class="react-directory-row undefined" id="bkmrk-readme.md-import-doc"><td class="react-directory-row-name-cell-large-screen" colspan="1" style="width: 35.0287%;"><div class="react-directory-filename-column"><svg aria-hidden="true" class="octicon octicon-file color-fg-muted" display="inline-block" fill="currentColor" focusable="false" height="16" overflow="visible" viewbox="0 0 16 16" width="16"><path d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg><div class="overflow-hidden"><div class="react-directory-filename-cell"><div class="react-directory-truncate">[README.md](https://github.com/n8n-io/n8n-hosting/blob/main/docker-compose/withPostgresAndWorker/README.md "README.md")</div></div></div></div></td><td class="react-directory-row-commit-cell" style="width: 44.1132%;"><div><div class="react-directory-commit-message">[import docker-compose examples from n8n-io/n8n](https://github.com/n8n-io/n8n-hosting/commit/4ea03df539c125b04471030e0e2b735b63d2566e "import docker-compose examples from n8n-io/n8n")</div></div></td><td style="width: 20.8582%;"><div class="react-directory-commit-age">last year</div></td></tr><tr class="react-directory-row undefined" id="bkmrk-docker-compose.yml-a"><td class="react-directory-row-name-cell-large-screen" colspan="1" style="width: 35.0287%;"><div class="react-directory-filename-column"><svg aria-hidden="true" class="octicon octicon-file color-fg-muted" display="inline-block" fill="currentColor" focusable="false" height="16" overflow="visible" viewbox="0 0 16 16" width="16"><path d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg><div class="overflow-hidden"><div class="react-directory-filename-cell"><div class="react-directory-truncate">[docker-compose.yml](https://github.com/n8n-io/n8n-hosting/blob/main/docker-compose/withPostgresAndWorker/docker-compose.yml "docker-compose.yml")</div></div></div></div></td><td class="react-directory-row-commit-cell" style="width: 44.1132%;"><div><div class="react-directory-commit-message">[add encryption key env variable](https://github.com/n8n-io/n8n-hosting/commit/a2e303b611ad00071588b43331fed96276c62834 "add encryption key env variable")</div></div></td><td style="width: 20.8582%;"><div class="react-directory-commit-age">8 months ago</div></td></tr><tr class="react-directory-row undefined" id="bkmrk-init-data.sh-import-"><td class="react-directory-row-name-cell-large-screen" colspan="1" style="width: 35.0287%;"><div class="react-directory-filename-column"><svg aria-hidden="true" class="octicon octicon-file color-fg-muted" display="inline-block" fill="currentColor" focusable="false" height="16" overflow="visible" viewbox="0 0 16 16" width="16"><path d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg><div class="overflow-hidden"><div class="react-directory-filename-cell"><div class="react-directory-truncate">[init-data.sh](https://github.com/n8n-io/n8n-hosting/blob/main/docker-compose/withPostgresAndWorker/init-data.sh "init-data.sh")</div></div></div></div></td><td class="react-directory-row-commit-cell" style="width: 44.1132%;"><div><div class="react-directory-commit-message">[import docker-compose examples from n8n-io/n8n](https://github.com/n8n-io/n8n-hosting/commit/4ea03df539c125b04471030e0e2b735b63d2566e "import docker-compose examples from n8n-io/n8n")</div></div></td><td style="width: 20.8582%;"><div class="react-directory-commit-age">last year</div></td></tr></tbody></table>

</div>## n8n with PostgreSQL and Worker

<div class="Box-sc-g0xbh4-0 kkSYPE" id="bkmrk-starts-n8n-with-post"><div class="Box-sc-g0xbh4-0 kxneWi" id="bkmrk-starts-n8n-with-post-1"><div class="Box-sc-g0xbh4-0 js-snippet-clipboard-copy-unpositioned DirectoryRichtextContent-module__SharedMarkdownContent--YORdJ" data-hpc="true"><article class="markdown-body entry-content container-lg"><div class="markdown-heading" dir="auto" style="text-align: justify;">[<svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgresAndWorker#n8n-with-postgresql-and-worker)</div>Starts n8n with PostgreSQL as database, and the Worker as a separate container.

## Start

<div class="markdown-heading" dir="auto" style="text-align: justify;">[<svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgresAndWorker#start)</div>To start n8n simply start docker-compose by executing the following command in the current folder.

**IMPORTANT:** But before you do that change the default users and passwords in the [`.env`](https://github.com/n8n-io/n8n-hosting/blob/main/docker-compose/withPostgresAndWorker/.env) file!

```
docker-compose up -d
```

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" style="text-align: justify;"><div class="zeroclipboard-container"><svg aria-hidden="true" class="octicon octicon-copy js-clipboard-copy-icon" data-view-component="true" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg></div></div>To stop it execute:

```
docker-compose stop
```

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" style="text-align: justify;"><div class="zeroclipboard-container"><svg aria-hidden="true" class="octicon octicon-copy js-clipboard-copy-icon" data-view-component="true" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg></div></div>## Configuration

<div class="markdown-heading" dir="auto" style="text-align: justify;">[<svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgresAndWorker#configuration)</div>The default name of the database, user and password for PostgreSQL can be changed in the [`.env`](https://github.com/n8n-io/n8n-hosting/blob/main/docker-compose/withPostgresAndWorker/.env) file in the current directory.

</article></div></div></div>

# Instalação, configuração e atualização N8N Docker

Link: [https://docs.n8n.io/hosting/installation/docker/](https://docs.n8n.io/hosting/installation/docker/)

# Docker Installation[\#](https://docs.n8n.io/hosting/installation/docker/#docker-installation "Permanent link")

[Docker](https://www.docker.com/) offers the following advantages:

- Install n8n in a clean environment.
- Easier setup for your preferred database.
- Can avoid issues due to different operating systems, as Docker provides a consistent system.

You can also use n8n in Docker with [Docker Compose](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/). You can find Docker Compose configurations for various architectures in the [n8n-hosting repository](https://github.com/n8n-io/n8n-hosting).

## Prerequisites[\#](https://docs.n8n.io/hosting/installation/docker/#prerequisites "Permanent link")

Before proceeding, install [Docker Desktop](https://docs.docker.com/get-docker/).

Linux Users

Docker Desktop is available for Mac and Windows. Linux users must install [Docker Engine](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/) individually for your distribution.

Self-hosting knowledge prerequisites

Self-hosting n8n requires technical knowledge, including:

<div class="admonition note" id="bkmrk-setting-up-and-confi" style="text-align: justify;">- Setting up and configuring servers and containers
- Managing application resources and scaling
- Securing servers and applications
- Configuring n8n

</div>n8n recommends self-hosting for expert users. Mistakes can lead to data loss, security issues, and downtime. If you aren't experienced at managing servers, n8n recommends [n8n Cloud](https://n8n.io/cloud/).

Latest and Next versions

n8n releases a new minor version most weeks. The `latest` version is for production use. `next` is the most recent release. You should treat `next` as a beta: it may be unstable. To report issues, use the [forum](https://community.n8n.io/c/questions/12).

Current `latest`: 1.72.1  
Current `next`: 1.73.1

## Starting n8n[\#](https://docs.n8n.io/hosting/installation/docker/#starting-n8n "Permanent link")

From your terminal, run:

<div class="highlight" id="bkmrk-1-2-3-docker-volume-" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
1
2
3
```

</td><td class="code">```
docker volume create n8n_data

docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n

```

</td></tr></tbody></table>

</div>This command will download all required n8n images and start your container, exposed on port `5678`. To save your work between container restarts, it also mounts a docker volume, `n8n_data`, to persist your data locally.

You can then access n8n by opening: [http://localhost:5678](http://localhost:5678/)

## Using alternate databases[\#](https://docs.n8n.io/hosting/installation/docker/#using-alternate-databases "Permanent link")

By default n8n uses SQLite to save credentials, past executions and workflows. n8n also supports PostgresDB configurable using environment variables as detailed below.

It's important to still persist data in the `/home/node/.n8n` folder as it contains n8n user data and even more importantly the encryption key for credentials. It's also the name of the webhook when the n8n tunnel is used.

If no directory is found, n8n creates automatically one on startup. In this case, existing credentials saved with a different encryption key can not be used anymore.

Keep in mind

Persisting the `/home/node/.n8n` directory even when using alternate databases is the recommended best practice, but not explicitly required. The encryption key can be provided using the `N8N_ENCRYPTION_KEY` [environment variable](https://docs.n8n.io/hosting/configuration/environment-variables/).

### PostgresDB[\#](https://docs.n8n.io/hosting/installation/docker/#postgresdb "Permanent link")

To use n8n with Postgres, provide the corresponding:

<div class="highlight" id="bkmrk-1-2-3-4-5-6-7-8-9-10" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
```

</td><td class="code">```
docker volume create n8n_data

docker run -it --rm \
 --name n8n \
 -p 5678:5678 \
 -e DB_TYPE=postgresdb \
 -e DB_POSTGRESDB_DATABASE=<POSTGRES_DATABASE> \
 -e DB_POSTGRESDB_HOST=<POSTGRES_HOST> \
 -e DB_POSTGRESDB_PORT=<POSTGRES_PORT> \
 -e DB_POSTGRESDB_USER=<POSTGRES_USER> \
 -e DB_POSTGRESDB_SCHEMA=<POSTGRES_SCHEMA> \
 -e DB_POSTGRESDB_PASSWORD=<POSTGRES_PASSWORD> \
 -v n8n_data:/home/node/.n8n \
 docker.n8n.io/n8nio/n8n

```

</td></tr></tbody></table>

</div>A complete `docker-compose` file for Postgres can be found [here](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgres).

## Setting timezone[\#](https://docs.n8n.io/hosting/installation/docker/#setting-timezone "Permanent link")

To define the timezone n8n should use, the environment variable `GENERIC_TIMEZONE` can be set. This gets used by schedule based nodes such as the Cron node.

The timezone of the system can also be set separately. This controls what some scripts and commands return like `$ date`. The system timezone can be set using the environment variable `TZ`.

Example using the same timezone for both:

<div class="highlight" id="bkmrk-1-2-3-4-5-6-7-8-9-do" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
1
2
3
4
5
6
7
8
9
```

</td><td class="code">```
docker volume create n8n_data

docker run -it --rm \
 --name n8n \
 -p 5678:5678 \
 -e GENERIC_TIMEZONE="Europe/Berlin" \
 -e TZ="Europe/Berlin" \
 -v n8n_data:/home/node/.n8n \
 docker.n8n.io/n8nio/n8n

```

</td></tr></tbody></table>

</div>## Updating[\#](https://docs.n8n.io/hosting/installation/docker/#updating "Permanent link")

From your Docker Desktop, navigate to the **Images** tab and select **Pull** from the context menu to download the latest n8n image:

[![Docker Desktop](https://docs.n8n.io/_images/hosting/installation/docker/docker_desktop.png)](https://docs.n8n.io/_images/hosting/installation/docker/docker_desktop.png)

You can also use the command line to pull the latest, or a specific version:

<div class="highlight" id="bkmrk-1-2-3-4-5-6-7-8-%23-pu" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
1
2
3
4
5
6
7
8
```

</td><td class="code">```
# Pull latest (stable) version
docker pull docker.n8n.io/n8nio/n8n

# Pull specific version
docker pull docker.n8n.io/n8nio/n8n:0.220.1

# Pull next (unstable) version
docker pull docker.n8n.io/n8nio/n8n:next

```

</td></tr></tbody></table>

</div>Stop the container and start it again. You can also use the command line:

<div class="highlight" id="bkmrk-1-2-3-4-5-6-7-8-9-10-1" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
```

</td><td class="code">```
# Get the container ID
docker ps -a

# Stop the container with ID container_id
docker stop [container_id]

# Remove the container with ID container_id
docker rm [container_id]

# Start the container
docker run --name=[container_name] [options] -d docker.n8n.io/n8nio/n8n

```

</td></tr></tbody></table>

</div>### Docker Compose[\#](https://docs.n8n.io/hosting/installation/docker/#docker-compose "Permanent link")

If you run n8n using a Docker Compose file, follow these steps to update n8n:

<div class="highlight" id="bkmrk-1-2-3-4-5-6-7-8-%23-pu-1" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
1
2
3
4
5
6
7
8
```

</td><td class="code">```
# Pull latest version
docker compose pull

# Stop and remove older version
docker compose down

# Start the container
docker compose up -d

```

</td></tr></tbody></table>

</div>## Further reading[\#](https://docs.n8n.io/hosting/installation/docker/#further-reading "Permanent link")

More information about Docker setup can be found in the README file of the [Docker Image](https://github.com/n8n-io/n8n/tree/master/docker/images/n8n).

## n8n with tunnel[\#](https://docs.n8n.io/hosting/installation/docker/#n8n-with-tunnel "Permanent link")

Danger

Use this for local development and testing. It isn't safe to use it in production.

To be able to use webhooks for trigger nodes of external services like GitHub, n8n has to be reachable from the web. n8n has a [tunnel service](https://github.com/localtunnel/localtunnel) which redirects requests from n8n's servers to your local n8n instance.

Start n8n with `--tunnel` by running:

<div class="highlight" id="bkmrk-1-2-3-4-5-6-7-8-dock" style="text-align: justify;"><table class="highlighttable"><tbody><tr><td class="linenos">```
1
2
3
4
5
6
7
8
```

</td><td class="code">```
docker volume create n8n_data

docker run -it --rm \
 --name n8n \
 -p 5678:5678 \
 -v n8n_data:/home/node/.n8n \
 docker.n8n.io/n8nio/n8n \
 start --tunnel

```

</td></tr></tbody></table>

</div>## Next steps[\#](https://docs.n8n.io/hosting/installation/docker/#next-steps "Permanent link")

- Learn more about [configuring](https://docs.n8n.io/hosting/configuration/environment-variables/) and [scaling](https://docs.n8n.io/hosting/scaling/overview) n8n.
- Or explore using n8n: try the [Quickstarts](https://docs.n8n.io/try-it-out/).