To rebuild a container from VS Code, open the Command Palette (Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on macOS), run Dev Containers: Rebuild Container, and let the editor discard the existing container and build a fresh one from your devcontainer.json. If you've edited Dockerfile layers, features, or mount definitions and the old container still looks stale, run Dev Containers: Rebuild Container Without Cache instead. Both commands require the Dev Containers extension, a Docker-compatible engine running on the host, and a workspace folder that contains a .devcontainer configuration.
That covers the ordinary case. The rest of this article deals with the situations where the ordinary case doesn't apply: rebuilds that silently reuse old layers, configurations that never produce a rebuild prompt, rebuild loops, and the difference between refreshing a container and rebuilding the image beneath it.
What a rebuild actually does inside VS Code
When you reopen a folder in a container, VS Code follows a short sequence. It reads the dev container configuration, checks whether a container already exists for that workspace, and if one does, attaches to it rather than building anything. That attachment behavior is the reason a rebuild command exists at all: ordinary reopening is designed to be fast and idempotent, not to pick up your Dockerfile edits.
Running a rebuild changes the sequence. The extension removes the existing container for the workspace, then builds an image from the configuration. Depending on how the config is written, the build either constructs a new image from a Dockerfile or composes one from a base image plus a list of features. After the image exists, VS Code creates a new container from it, starts it, and runs the lifecycle hooks defined in devcontainer.json in their documented order: initializeCommand on the host, then onCreateCommand, updateContentCommand, and postCreateCommand inside the container, followed by postStartCommand each time the container starts and postAttachCommand when the editor attaches. Your extensions declared in the config are then installed into that container, and the workspace is mounted or copied in.
Two consequences follow. First, anything stored only inside the container's writable layer disappears. Files in the workspace folder survive because they live on the host, but packages you installed by hand, shell history, and databases written to a non-mounted path do not. Second, the rebuild is only as fresh as its cache. Docker reuses unchanged layers, so a rebuild can complete in seconds and still produce an image containing an outdated package index. That's not a bug; it's the cache doing its job, and it's the single most common source of "I rebuilt and nothing changed."
Prerequisites before your first rebuild
Four things need to be true, and each one has a cheap check.
The Dev Containers extension is installed. Open the Extensions view and search for "Dev Containers" (publisher Microsoft). Remote - Containers was folded into this extension, so an older install may need updating rather than a second extension.
A Docker-compatible engine is running and reachable. Docker Desktop, Docker Engine on Linux, Podman with the Docker-compatible socket, or another supported runtime all work. From a terminal, docker version should print both a client and a server section. If the server section is missing, the engine isn't running or your user lacks socket permissions.
The workspace has a dev container configuration. It lives in .devcontainer/devcontainer.json, or in .devcontainer.json at the repository root. A config that references a Dockerfile usually also has that Dockerfile in the same folder.
You know whether the config is image-based or Dockerfile-based. Open the file and look for a build object (Dockerfile or Compose) versus a top-level image string. This determines which rebuild command is appropriate and whether a Docker Compose rebuild is involved.
If any of these fail, the rebuild command either won't appear in the Command Palette or will fail immediately with a message naming the missing piece. Fix the prerequisite rather than retrying the command.
The step-by-step rebuild
This procedure assumes the prerequisites above and a workspace that has already opened successfully in a container at least once.
1: Save your work outside the container's writable layer. Anything in the mounted workspace is safe. Anything you created in /tmp, in a home directory not backed by a mount, or inside a running database without a volume will be lost. If you need it, copy it to the workspace or a named volume first. 2: Open the Command Palette. Ctrl+Shift+P on Windows and Linux, Cmd+Shift+P on macOS. 3: Type "rebuild" and read the options before choosing. You should see entries beginning with "Dev Containers: Rebuild Container," "Dev Containers: Rebuild Container Without Cache," and, if the workspace isn't currently attached, "Dev Containers: Reopen in Container." 4: Run "Dev Containers: Rebuild Container" for a normal refresh. This is the right choice after editing devcontainer.json, adding a feature, changing a mount, or updating a Dockerfile line that already invalidates the relevant layer. 5: Run "Dev Containers: Rebuild Container Without Cache" when the normal rebuild produces an image that still behaves like the old one, or when you've changed something upstream of a cached layer such as a base image tag or an apt-get update line that Docker considers unchanged. 6: Watch the build log. VS Code opens a terminal panel showing the Dev Containers log. Build output from Docker appears there, followed by lifecycle hook output. Read it rather than switching away; failures surface here first. 7: Wait for the attach. On success, the bottom-left status bar shows the remote indicator, the terminal prompt returns inside the container, and extensions begin installing. The window reloads once. 8: Verify the result. Run a command that reflects your change, such as node --version, python --version, or a package you just added to the Dockerfile. Check that your workspace files are present and that any named volume still has its data.
The success check matters more than it sounds. A rebuild that attaches to a container without error can still have skipped your change if the change was in a file Docker didn't consider part of the build context, or if a Compose override supplied a different image.
If you're working from a folder that isn't open in a container at all, the rebuild command won't rebuild anything useful. Use Dev Containers: Reopen in Container first; it builds and attaches in one step.
Choosing among the rebuild commands
The command names are similar enough that picking the wrong one is routine. Here's how they differ in practice.
| Command | What it does | When it's the right call | What it does not do |
|---|---|---|---|
| Rebuild Container | Removes the workspace container and rebuilds using Docker's layer cache | Config edits, feature additions, mount changes | Bypass a stale cached layer |
| Rebuild Container Without Cache | Same removal, but passes a no-cache build so every layer is re-executed | Base image updates, package index refreshes, suspected stale layers | Speed things up, or fix config errors |
| Reopen in Container | Attaches to an existing container, or builds one if none exists | First open, or after closing the window | Discard an existing container |
| Rebuild and Reopen in Container | Combines removal, rebuild, and attach in a single command | A clean restart of the whole cycle | Preserve container-local state |
The no-cache variant is meaningfully slower, sometimes by several minutes on configs that install large toolchains, because it re-downloads and re-runs every instruction. Use it deliberately, not by default. A reasonable habit is to try the cached rebuild first and escalate only when the result contradicts the change you made.
Docker Compose configurations add a wrinkle. When devcontainer.json uses dockerComposeFile, a rebuild rebuilds the services defined there, and other services in the same Compose project may keep running or be recreated depending on their definitions. If your workspace depends on a database service, confirm after the rebuild that the database container is the one you expect and that its volume is still attached.
Rebuilds that seem to do nothing
The symptom is familiar: you edited the Dockerfile, ran a rebuild, and the container still has the old tool version. Work through these causes in order, starting with the least destructive.
The change lives in a cached layer. Docker treats each instruction as a cache key built from the instruction and everything before it. Editing a line near the top invalidates everything below; editing a line near the bottom invalidates only that line and later ones. An apt-get install with an unchanged package list will happily reuse a layer built weeks ago. Running the no-cache rebuild confirms whether this is the cause, since it's the only variant that re-executes every instruction.
The configuration isn't the one being used. Multiple configs in a repository, a Compose override file, or a .devcontainer.json at the root shadowing a .devcontainer/devcontainer.json can all mean VS Code reads a different definition than the one you edited. The build log names the configuration path it used, so check that line against the file you changed.
The container was rebuilt but the image wasn't. If the config specifies an image string without a build section, a rebuild recreates the container from whatever that image currently is locally. It doesn't pull a newer tag. Pull the image explicitly or switch to a Dockerfile-based config if you need build-time control.
A lifecycle hook is overwriting your change. A postCreateCommand that installs a pinned version of a tool will undo a Dockerfile change on every rebuild. Search the config for hooks that touch the same tool you modified.
The build failed and you missed it. A failed build leaves the old container in place in some flows, so the window looks normal. The log terminal usually still holds the error. Scroll to the first failure, not the last line.
Persistent failures that mention permission denied on the Docker socket, or that the Docker daemon can't be reached, point at the engine rather than the configuration. Those need a host-side fix: starting Docker Desktop, adding your user to the docker group on Linux, or correcting the socket path in the extension settings.
When rebuilds loop or fail outright
A rebuild loop, where the window reloads repeatedly or the attach never completes, is usually a lifecycle hook that exits non-zero or a postStartCommand that kills the process it depends on. The build log shows hook output in order, so the last hook to print before the loop is the one to inspect. Commenting out hooks one at a time, or moving a suspect command from postCreateCommand to postStartCommand, narrows it down.
Out-of-disk errors during the build have a specific remedy: docker system prune removes stopped containers, dangling images, and unused networks, and is safe for dev container work as long as you're not relying on stopped containers elsewhere. It does not remove named volumes, which is good, since those may hold your data. Build cache alone can consume many gigabytes on a machine used for several configurations.
If a rebuild fails with an error about the build context or a missing Dockerfile, confirm the path in the build object is relative to the configuration file, not the workspace root. This trips people up when the config lives in a subfolder.
There's a point where further local debugging stops being productive. If the Docker engine itself fails to start, if builds fail with storage driver or kernel-level errors, or if the failure persists after pruning and a known-good minimal configuration toggles the same error on and off, hand it to whoever administers the host or your organization's container tooling. Reinstalling Docker or repartitioning a disk is outside what a VS Code rebuild can fix, and guessing at it risks the data in your volumes.
Preserving state across rebuilds
Because a rebuild discards the container's writable layer, state worth keeping has to live somewhere else. There are three practical places.
The workspace folder is mounted into the container by default and survives every rebuild, which makes it the right home for source code, configuration, and anything small you'd otherwise leave on the container's desktop.
Named volumes declared in devcontainer.json under mounts or in a Compose file persist independently of the container and are the standard place for package caches, database data directories, and language-specific caches such as a pip or npm cache. A volume attached to a path the rebuild would otherwise wipe is what makes a rebuild fast rather than merely correct.
Bind mounts from the host work too, and are useful for credentials and SSH keys, though they carry permission-mapping complications on Linux hosts when the container user's UID differs from yours.
One habit pays for itself: before the first rebuild of an unfamiliar configuration, check docker ps and inspect which paths are mounted. Anything written to an unmounted path is at risk, and knowing which paths those are takes a minute.
Rebuild versus recreate: a distinction worth keeping straight
These two get used interchangeably in conversation, and the confusion causes real problems when someone expects one and gets the other.
A recreate is what the rebuild commands do to the container: the existing container is destroyed and a new one is created. A rebuild concerns the image, and whether its layers are re-executed depends on the cache. A no-cache rebuild does both. A cached rebuild may do the first without meaningfully doing the second.
That distinction explains a common frustration. Someone changes a package version in the Dockerfile, runs a cached rebuild, and finds the old version installed. The container was genuinely recreated, which is why the terminal looks fresh and extensions reinstalled, but the layer that installs the package was reused, so the image content didn't change. If the goal is to pick up a changed instruction, and especially a changed upstream instruction like a base image tag, the no-cache variant is the one that matches the intent.
It also helps when reasoning about data. A recreate always discards container-local state; a pull of a newer base image might change the image without any container being recreated at all, which is why image-based configs can look stale until you pull explicitly.
Keeping rebuilds fast enough to use
The no-cache rebuild is the reliable tool, but it shouldn't be the routine one. A few structural choices keep the ordinary cached rebuild quick enough that you'll actually run it.
Order Dockerfile instructions from least to most frequently changed. Base image and system packages first, dependency manifests next, then the dependency install step, then your application source last. With that order, editing source code invalidates only the final layers and the cached rebuild finishes in seconds.
Keep the build context small. A .dockerignore that excludes node_modules, build outputs, and large data directories stops Docker from sending gigabytes to the daemon on each build and from invalidating cache keys when unrelated files change.
Declare caches as volumes rather than reinstalling them. A pip cache or npm cache on a named volume survives rebuilds and turns a multi-minute dependency install into a short verification pass, which matters most on the no-cache path where you've already paid the layer-re-execution cost.
Finally, prefer features and image-based configs for tooling that rarely changes, and reserve Dockerfile instructions for things you actively iterate on. Each layer you don't need to invalidate is a rebuild you don't have to wait through.
FAQ
Does rebuilding delete my files? Files in the mounted workspace folder survive. Files anywhere else inside the container, including home-directory files not backed by a volume, are lost. Databases and caches survive only if they're on named volumes or bind mounts.
Why doesn't Rebuild Container pick up my Dockerfile change? Most often because Docker reused a cached layer that the change didn't invalidate, or because the configuration being built isn't the one you edited. The build log names the config path; check it, then escalate to the no-cache rebuild to rule out caching.
Can I rebuild without losing my running processes? No. A rebuild destroys the container and everything running in it. If you need a process to persist, move its state to a volume and plan to restart it after the rebuild, or use postStartCommand to bring it back automatically.
What if the rebuild command doesn't appear in the Command Palette? Confirm the Dev Containers extension is installed and enabled, that a Docker engine is reachable, and that the workspace actually contains a dev container configuration. When a prerequisite is missing, the command is often filtered out rather than shown greyed out.