DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Use working_dir in a Docker Compose File

Docker Compose’s working_dir sets the in-container directory for one service’s commands. This guide explains syntax, image WORKDIR overrides, mounts, lifecycle hooks, project-directory differences, and troubleshooting.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

working_dir is a service-level Docker Compose setting that chooses the directory inside a container where that service’s commands run. It overrides the image’s Dockerfile WORKDIR; it does not change the host directory Compose uses to find the project, resolve a relative build context, or load files. Set it under the service that needs the different in-container directory, then verify it with a command such as pwd.

What working_dir does

In a Compose file, working_dir changes the process working directory for one service. Commands started by that service—its main command, an overridden entrypoint, and applicable lifecycle-hook commands—start in the directory you specify inside the container.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The setting is equivalent to telling the container runtime to use a different current directory for that service. It is not a host-side cd, and it does not relocate your Compose project. A simple service definition looks like this:

services:
  game-server:
    image: example/game-server:latest
    working_dir: /opt/game
    command: ./start-server.sh

When the container starts, ./start-server.sh is resolved from /opt/game inside the container. The same path has no direct meaning on your host unless you separately mount a host directory there.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

How Compose chooses the initial directory

The image’s Dockerfile WORKDIR

Container images can declare a default directory with Dockerfile WORKDIR. If a Compose service does not set working_dir, commands normally inherit that image-defined directory. For example, an image containing WORKDIR /app starts its default command in /app.

A Compose override

Adding working_dir at service level overrides the directory supplied by the image. This lets the same image run different services from different locations:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
services:
  api:
    image: example/app:2.4
    working_dir: /srv/api
    command: python main.py

  worker:
    image: example/app:2.4
    working_dir: /srv/worker
    command: python worker.py

Both containers use the same image, but each process resolves relative paths from its own configured directory. The override affects the service using it; it does not rewrite the image and does not change another service that uses the same image.

Basic configuration syntax

Use a service-level key

Place working_dir beside keys such as image, build, command, and volumes. Do not put it at the top level of the Compose document.

services:
  frontend:
    build:
      context: .
    working_dir: /workspace/frontend
    command: npm run dev

The value is a container path. Absolute paths are easiest to reason about because they do not depend on another directory setting.

Make relative commands intentional

A command such as ./scripts/run.sh, npm run build, or python src/manage.py is interpreted from the configured working directory. If the command unexpectedly reports that a file is missing, first check whether the file exists at the path formed by that directory plus the command’s relative path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
services:
  tools:
    image: python:3.12
    working_dir: /workspace
    command: python scripts/check.py
    volumes:
      - ./project:/workspace

Here, the host project is mounted at /workspace, so scripts/check.py is expected at /workspace/scripts/check.py in the container.

Working directory versus host paths

The most common misunderstanding is treating working_dir as a way to change where Compose operates on the host. It is not. The key controls an in-container directory after the service is created.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
Setting or concept Scope What it controls Source of the default
working_dir Container service The directory in which that service’s commands run Compose value overrides the image default
Dockerfile WORKDIR Container image The image’s default process directory Dockerfile used to build the image
--project-directory Host-side Compose project The alternate base directory for the Compose project By default, the path of the first specified Compose file
build.context Host-side build input The directory sent as build context A relative context is resolved from the Compose file location in the older Compose reference

If your goal is “run Compose as though I launched it from another project directory,” use the CLI’s --project-directory option rather than adding working_dir to a service. The Docker Compose CLI reference describes the default project directory as the path of the first specified Compose file and allows you to replace it with this flag.

docker compose --project-directory /srv/projects/my-game up

This changes the host-side project base used by the Compose command. It does not change the current directory of a process inside a container. You may need both settings in a real project: --project-directory for Compose’s host-side project handling and working_dir for a service’s in-container commands.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How relative build paths interact with working_dir

Build context is selected before the image is built and is a host-side concern. An older reference in the Compose repository states that a relative build.context is interpreted relative to the Compose YAML file location, and that this directory is sent to the Docker daemon as build context. Under that description, changing a service’s working_dir cannot redirect the build context.

services:
  game:
    build:
      context: ./docker/game
    working_dir: /opt/game
    command: ./run.sh

In this example, ./docker/game belongs to the host-side path calculation for the Compose file; /opt/game belongs to the container process. Because path handling can evolve between Compose implementations and versions, check the current build documentation when a relative context is critical, especially in a multi-file project.

A complete example with a bind mount

The following pattern makes the relationship between host files, the mount point, and the working directory explicit:

services:
  editor:
    image: node:22
    working_dir: /workspace
    volumes:
      - ./game-ui:/workspace
    command: npm run dev
  1. Compose creates the editor service from the Node image.
  2. The host directory ./game-ui is mounted at /workspace inside the container.
  3. The service process starts in /workspace because of working_dir.
  4. npm run dev reads the project files from that mounted directory.

The mount is what makes host files visible in the container. working_dir only selects the directory from which the command starts. If you change the mount destination but leave working_dir unchanged, the command may start in a directory that does not contain the project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Commands for checking the effective directory

Check a running service

Use an ephemeral command with docker compose run to print the directory Compose applies to the service:

docker compose run --rm editor pwd

The output should be the configured container path, such as /workspace. This is useful because it tests the service configuration without relying on the application’s own logging.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Inspect the directory and files together

docker compose run --rm editor sh -lc 'pwd; ls -la'

This separates two failure types: an incorrect current directory and a missing or incorrectly mounted file. If the directory is right but the expected files are absent, inspect the volume source and destination rather than changing working_dir.

Check the service’s rendered configuration

docker compose config

Review the rendered service and confirm that working_dir appears under the intended service with the expected value. This also helps detect YAML indentation errors and variable interpolation that produced an unexpected path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Lifecycle hooks and working_dir

Compose’s services reference gives a specific rule for a pre_start lifecycle hook: its working_dir is the directory in which the hook command runs. If the hook does not set its own directory, the hook runs in the same working directory as the main service command.

That distinction matters when preparation scripts use relative paths. A hook can intentionally run from a separate directory, or it can inherit the service directory so that both phases see the same files:

services:
  game:
    image: example/game:1.0
    working_dir: /opt/game
    pre_start:
      - command: ./scripts/prepare.sh
    command: ./scripts/start.sh

When diagnosing a hook failure, check the hook’s effective directory separately from the main command’s directory. A script that succeeds interactively from /opt/game can fail if a hook-specific setting causes it to run elsewhere.

Choosing a path that the container can use

Match the image layout

Before overriding the image’s default, identify where the image stores its application files. An override such as /workspace is useful only if the command and its dependencies are available there, either in the image or through a mount.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Match the mount destination

For development services, use the same container path for the bind mount destination and working_dir when the command should run against mounted source files. This avoids commands starting in an unrelated image directory.

Keep scripts and configuration paths consistent

Changing the current directory can affect relative paths in shell scripts, package-manager commands, test runners, and application configuration. If a script itself changes directories, document that separately; Compose sets the initial directory only.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Common mistakes and their fixes

Putting the key at the wrong YAML level

This is invalid because working_dir belongs to a service:

working_dir: /workspace
services:
  app:
    image: example/app

Move it under the service:

services:
  app:
    image: example/app
    working_dir: /workspace

Run docker compose config after editing to catch structural errors before starting containers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Expecting it to change the host project directory

If Compose is loading the wrong file or resolving a project relative to the wrong host location, changing working_dir will not help. Select the Compose file explicitly or use --project-directory for the host-side project base.

Using a host path as though it were a container path

working_dir: ./src does not mean “use the src directory beside the YAML file.” It is a directory value for the container. If you need host files there, define a volume whose container destination is the same path, for example ./src:/workspace together with working_dir: /workspace.

Leaving relative commands unchanged after an override

An image may have been designed for /app, with scripts and configuration referenced relative to that directory. Overriding to /workspace can make those relative references fail. Either mount the required files at the new path, use absolute paths where appropriate, or retain the image’s default directory.

Debugging the wrong container

In a multi-service project, each service can have a different setting. Check the service name in the Compose command and inspect that service’s configuration rather than assuming all containers share one working directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why “working_dir is not working”

The command is an absolute path

An absolute command path such as /usr/local/bin/start does not depend on the current directory. The setting may be applied correctly even though the application’s launch path looks unchanged.

The entrypoint changes directories

An image entrypoint or shell wrapper can execute cd before launching the application. In that case, Compose supplies the initial directory, but the wrapper deliberately changes it. Inspect the entrypoint script and test with pwd as the command to isolate Compose behavior.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

The files are not mounted where you expect

A correct working directory does not copy files into the container. Verify the mount destination with ls -la and confirm that the host source directory is the one you intended.

Interpolation changed the value

If the value uses an environment variable, render the configuration with docker compose config. A missing or differently valued variable can produce a path other than the one you typed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The selected Compose file is not the one you edited

When multiple Compose files or project directories are involved, confirm which file is being loaded. The CLI’s project-directory behavior is separate from the service’s working_dir; changing one does not silently change the other.

When to use each mechanism

Use working_dir when

  • A service must run its command from a specific directory inside the container.
  • You are reusing one image for services whose application roots differ.
  • A bind mount has a known container destination and the command should start there.
  • A lifecycle hook needs a deliberate in-container directory.

Use Dockerfile WORKDIR when

  • You control the image and want a sensible default for every container using it.
  • The image’s files and startup command are designed around one stable application root.

Use --project-directory when

  • You need to change the host-side base directory for Compose project operations.
  • You are invoking Compose from a different location than the project’s Compose file.

Use build.context when

  • You need to select which host directory is sent to the image build.
  • The Dockerfile needs access to a particular set of files during docker compose build.

A practical setup and verification workflow

  1. Identify the service whose command needs a different in-container directory.
  2. Check the image’s Dockerfile WORKDIR and the locations of its scripts and application files.
  3. Choose an absolute container path, such as /workspace or /opt/game.
  4. Put working_dir under that service, at the same level as image, build, and command.
  5. If source files come from the host, mount them at the selected container path.
  6. Run docker compose config and confirm the rendered value and service name.
  7. Run docker compose run --rm SERVICE pwd to verify the effective directory.
  8. Run docker compose run --rm SERVICE sh -lc 'pwd; ls -la' to verify both the directory and its contents.
  9. Start the normal service and inspect any entrypoint or hook that may change directories afterward.

Frequently asked questions

Does working_dir override Dockerfile WORKDIR?

Yes. The Compose service value overrides the working directory specified by the image. Without the Compose value, the image’s declared default is used.

Does it change where relative volume or build paths are resolved?

No. It is a container-side process setting. Host-side project and build-path behavior is handled by Compose’s project-directory and build-context rules, not by working_dir.

Can two services using one image have different working directories?

Yes. Set a different service-level value for each service. The image remains unchanged.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What directory does a pre_start hook use?

The hook uses its own working_dir when one is set. Otherwise, the reference specifies that it uses the same working directory as the main service command.

How can I prove which directory a service uses?

Run docker compose run --rm SERVICE pwd, then list files with docker compose run --rm SERVICE sh -lc 'pwd; ls -la'.

The rule to remember

working_dir answers one question: “Where inside this service’s container should its process start?” Use Dockerfile WORKDIR for an image-wide default, --project-directory for the host-side Compose project base, and build.context for host files sent to a build. Keeping those scopes separate prevents most path and “working directory” errors in Compose projects.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.