Skip to main content
RapidDev - Software Development Agency
replit-tutorial

How to use Docker with Replit

Replit does not support Dockerfiles directly. Instead, it uses Nix for environment customization through two files: replit.nix for system-level packages and .replit for runtime configuration. You add system dependencies like ffmpeg, ImageMagick, or specific language versions by listing them in replit.nix, and configure run commands, ports, and environment variables in .replit. This gives you Docker-like environment control without writing Dockerfiles.

What you'll learn

  • Understand why Replit uses Nix instead of Docker and how they compare
  • Edit replit.nix to install system-level packages like databases, media tools, and compilers
  • Configure .replit for custom run commands, environment variables, and port mappings
  • Troubleshoot common Nix build errors and package resolution issues
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Advanced8 min read20-30 minutesAll Replit plans. Nix packages count against storage quota (2 GiB on Starter, 50 GiB on Core/Pro).March 2026RapidDev Engineering Team
TL;DR

Replit does not support Dockerfiles directly. Instead, it uses Nix for environment customization through two files: replit.nix for system-level packages and .replit for runtime configuration. You add system dependencies like ffmpeg, ImageMagick, or specific language versions by listing them in replit.nix, and configure run commands, ports, and environment variables in .replit. This gives you Docker-like environment control without writing Dockerfiles.

Customize Your Replit Environment with Nix Instead of Docker

This tutorial explains how to create tailored development environments in Replit using Nix, which replaces Docker as the system-level package manager. You will learn to edit replit.nix to add system dependencies, configure .replit for custom run commands and environment variables, and troubleshoot common Nix errors. This guide is for developers who need specific system packages, language versions, or build tools that are not included in Replit's default environment.

Prerequisites

  • A Replit account (any plan)
  • A Replit App where you need custom system packages
  • Basic understanding of what system-level dependencies are (compilers, libraries, CLI tools)
  • Familiarity with the Replit workspace (file tree, Shell, Run button)
  • No prior Nix experience required

Step-by-step guide

1

Reveal hidden configuration files

The replit.nix and .replit files are hidden by default in the file tree. Click the three-dot menu (vertical dots) at the top of the file tree panel and select 'Show hidden files.' You should now see .replit and replit.nix in your project root alongside your source code. If replit.nix does not exist yet, you will create it in the next step. The .replit file should already exist with basic configuration.

Expected result: Hidden files are visible in the file tree. You can see .replit and potentially replit.nix in the project root.

2

Create or edit replit.nix to add system packages

The replit.nix file defines which system-level packages are available in your environment. This is equivalent to the RUN apt-get install lines in a Dockerfile. Open replit.nix (or create it if it does not exist) and define a deps array listing the packages you need. Each package uses the pkgs. prefix followed by the Nix package name. Search for available packages at search.nixos.org/packages to find the exact names. Common packages include language runtimes, database clients, image processing tools, and build compilers.

typescript
1{ pkgs }: {
2 deps = [
3 pkgs.nodejs-20_x
4 pkgs.python311
5 pkgs.ffmpeg
6 pkgs.imagemagick
7 pkgs.postgresql_16
8 pkgs.redis
9 pkgs.curl
10 pkgs.jq
11 ];
12}

Expected result: The replit.nix file is saved with your package list. The packages are not installed yet; that happens when you restart the Shell.

3

Reload the Nix environment

After modifying replit.nix, you need to restart the Shell for Nix to pick up the changes and install the new packages. Type 'exit' in the Shell tab and press Enter. Replit will close the current Shell session, rebuild the Nix environment with your new packages, and open a fresh Shell. This process can take 30 seconds to several minutes depending on how many packages you added. Watch the Shell output for any error messages during the rebuild.

typescript
1# Type this in Shell to restart and rebuild the Nix environment:
2exit

Expected result: The Shell restarts and the new packages are available. You can verify by running the package commands, such as 'ffmpeg --version' or 'python3 --version'.

4

Configure the .replit file for custom runtime behavior

The .replit file controls how your app runs, similar to a docker-compose.yml file. Open .replit and configure the entrypoint, run command, deployment settings, port mappings, and environment variables. The run command executes when you click the Run button. You can chain multiple commands with && or run multiple processes with & and wait. Environment variables can be set under [run.env] for development or in Secrets for sensitive values.

typescript
1entrypoint = "src/main.py"
2run = "pip install -r requirements.txt && python src/main.py"
3
4[nix]
5channel = "stable-24_05"
6
7[run.env]
8PYTHONPATH = "${REPL_HOME}/src"
9FLASK_ENV = "development"
10
11[deployment]
12run = ["sh", "-c", "python src/main.py"]
13build = ["sh", "-c", "pip install -r requirements.txt"]
14deploymentTarget = "cloudrun"
15
16[[ports]]
17localPort = 5000
18externalPort = 80
19
20hidden = [".config", "__pycache__", ".git", "venv"]

Expected result: Pressing Run executes your custom command chain. The environment variables are available in your application. The Preview pane shows your app on the configured port.

5

Add packages via the quick Nix shortcut in .replit

For simple package additions, you can skip editing replit.nix entirely and use the [nix] packages shortcut in your .replit file. This is faster for adding one or two packages but does not support advanced Nix expressions. List packages under [nix] packages as an array of strings. This approach and replit.nix are complementary; packages from both sources are installed.

typescript
1[nix]
2channel = "stable-24_05"
3packages = ["cowsay", "htop", "tree"]

Expected result: After restarting Shell with 'exit,' the quick-added packages are available. Run 'cowsay hello' or 'htop' to verify.

6

Run multiple processes simultaneously

Docker Compose often runs multiple services (server, worker, database) together. In Replit, you can achieve the same by using a compound run command in .replit. Use the & operator to run processes in the background and 'wait' to keep the main process alive. This is useful for running a frontend dev server alongside a backend API, or an application alongside a background worker.

typescript
1# Run a Flask API and a React frontend simultaneously
2run = "python api/server.py & cd frontend && npm start & wait"

Expected result: Both processes start when you click Run. The Console shows output from all processes interleaved. You can access each process on its configured port.

7

Troubleshoot common Nix errors

The most common Nix error is 'nix error: building nix env: exit status 1,' often with output trimmed to the last 20 lines. This usually means a package name is wrong, the Nix channel is too old for the requested package, or an unfree package is being used without being enabled. To debug, check the error output in Shell, verify package names at search.nixos.org/packages, try updating the channel in .replit, and look for diagnostic info by running 'cat /run/replit/env/error' in Shell.

typescript
1# Diagnose Nix environment errors
2cat /run/replit/env/error
3
4# Check which Nix packages are currently installed
5nix-env -q
6
7# Search for a package name locally
8nix-env -qaP | grep -i ffmpeg

Expected result: You can identify the root cause of Nix build failures and fix them by correcting package names, updating the channel, or finding alternative packages.

Complete working example

replit.nix
1# replit.nix - System-level environment configuration
2# This is Replit's equivalent of a Dockerfile for system packages.
3# Search for packages at: https://search.nixos.org/packages
4
5{ pkgs }: {
6 deps = [
7 # Language runtimes
8 pkgs.nodejs-20_x
9 pkgs.python311
10 pkgs.python311Packages.pip
11
12 # Language tools
13 pkgs.nodePackages.typescript-language-server
14 pkgs.nodePackages.prettier
15
16 # Database clients
17 pkgs.postgresql_16
18
19 # Media processing
20 pkgs.ffmpeg
21 pkgs.imagemagick
22
23 # Build tools
24 pkgs.gcc
25 pkgs.gnumake
26 pkgs.pkg-config
27
28 # CLI utilities
29 pkgs.curl
30 pkgs.jq
31 pkgs.tree
32 pkgs.htop
33
34 # Native library dependencies
35 # (needed by some npm packages with native bindings)
36 pkgs.libuuid
37 pkgs.zlib
38 ];
39}

Common mistakes when using Docker with Replit

Why it's a problem: Using wrong package names (e.g., pkgs.nodejs instead of pkgs.nodejs-20_x)

How to avoid: Search for the exact package name at search.nixos.org/packages. Nix package names follow specific conventions that differ from apt or brew.

Why it's a problem: Forgetting to restart Shell after editing replit.nix

How to avoid: Type 'exit' in Shell and press Enter after every change to replit.nix. The environment only rebuilds on Shell restart.

Why it's a problem: Using an outdated Nix channel that does not include newer packages

How to avoid: Update the channel in .replit to a recent stable version like 'stable-24_05'. Older channels may not have newer package versions available.

Why it's a problem: Installing too many large packages and running out of storage

How to avoid: Check your storage usage in the Resources panel. Remove packages you do not need. Starter plans have only 2 GiB, which fills quickly with large packages.

Why it's a problem: Trying to use a Dockerfile or docker-compose.yml in Replit

How to avoid: Replit does not support Docker. Translate your Dockerfile's apt-get install commands to Nix package equivalents in replit.nix, and your CMD/ENTRYPOINT to the run command in .replit.

Best practices

  • Always verify Nix package names at search.nixos.org/packages before adding them to replit.nix
  • Use a stable Nix channel (like stable-24_05) rather than unstable to avoid breaking changes
  • Run 'exit' in Shell after every replit.nix change to rebuild the environment
  • Keep replit.nix lean with only the packages you actually need since they count against storage quota
  • Use the .replit [nix] packages shortcut for quick one-off CLI tools and replit.nix for complex dependencies
  • Set non-sensitive environment variables in [run.env] in .replit and sensitive ones in Tools > Secrets
  • Run 'cat /run/replit/env/error' to diagnose Nix build failures when error output is truncated
  • Test your Nix configuration changes in development before deploying, as the same environment applies in production

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I need to set up a Replit environment that has Node.js 20, Python 3.11, ffmpeg for video processing, and PostgreSQL. In Docker I would write a Dockerfile, but Replit uses Nix. Help me create the replit.nix and .replit configuration files with the correct package names.

Replit Prompt

Configure the replit.nix file for this project. I need the following system packages: Node.js 20, ffmpeg, ImageMagick, and the PostgreSQL client. Also update .replit to set the correct run command and add a [run.env] section with NODE_ENV=development.

Frequently asked questions

No. Replit does not support Docker or Dockerfiles. Instead, use replit.nix for system-level packages and .replit for runtime configuration. The replit.nix file serves a similar purpose to the RUN commands in a Dockerfile.

Nix is a package manager that creates reproducible, isolated environments. Replit uses it because it allows deterministic builds where every user gets the exact same system packages, regardless of when they run the project. This is similar to Docker's reproducibility but integrated directly into the Replit platform.

Search for packages at search.nixos.org/packages. Enter the tool name (like 'ffmpeg' or 'nodejs') and the search results show the exact Nix package name to use in your replit.nix file. Always use the pkgs. prefix when adding packages.

Yes. Nix packages consume storage from your plan's allocation. However, Replit maintains a large pre-built cache of common packages that installs faster and may not count fully against quota. Check the Resources panel for current storage usage.

No. Replit does not provide root or sudo access. You install system packages through replit.nix, not through apt-get or yum. This is a security restriction of the platform.

Most popular packages are available in the Nix repository. If a package truly does not exist, you can compile it from source in your project directory using Shell commands, or look for an alternative package that provides similar functionality.

Yes. The RapidDev engineering team can help configure Nix environments for projects with complex system dependencies, native binary requirements, or multi-language stacks that require careful package coordination.

Yes. The same replit.nix packages are available in your deployed environment. The build and run commands in the [deployment] section of .replit use the same Nix-provided tools and packages.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.