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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Docker volumes and bind mounts determine which files a container can access; Docker networks determine which services can communicate. Use a named volume for persistent container data, a bind mount when the host and container need the same files, and a network to define service connectivity. These choices work together rather than competing with one another.

Docker volumes vs. bind mounts: where container files live

A container has a writable layer, but files stored there are tied to that container’s lifecycle. Removing the container removes its writable layer. To keep data outside that lifecycle, use a volume or a bind mount, depending on who needs to access the files.

Choice Where the source data lives Good fit Main considerations
Named volume Docker-managed storage on the host Persistent application or database data generated and used by containers Persistence, Docker-managed backup or migration, sharing between containers, and whether direct host-path access is needed
Bind mount A chosen host file or directory Development source files, host configuration, or deliberate host/container file sharing Host-path portability, permissions, container write access, and exposure of host files

Use a named volume for persistent container data

Docker describes volumes as its preferred mechanism for persisting data generated and used by containers. Docker manages their storage location, and volume contents are separate from a particular container’s writable layer. A volume remains available when no running container uses it, and removing a container does not by itself remove the volume. Docker also identifies sharing, backup or migration, and performance-sensitive I/O as volume use cases; these are qualitative recommendations, not a guarantee of performance in every setup. Docker’s volume documentation explains the lifecycle and management options.

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

In Compose, declare a named volume at the top level and list it under the service that needs access. Compose creates it on up if it does not already exist. For example:

#1 Best Overall
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
services:
  app:
    image: example-app
    volumes:
      - app-data:/var/lib/example-app

volumes:
  app-data:

The volume name in the service connects that container path to Docker-managed storage. It is not intended as a regular, portable host path for editing files directly.

Use a bind mount when host and container need the same files

A bind mount maps a specific host path into a container path. It is useful for editing source code on the host while an application runs in a container, sharing configuration, or deliberately writing generated files back to the host. Because the container can access the mounted content through normal filesystem operations, select the source path and permissions deliberately. Docker’s bind-mount guide describes these use cases and options.

For a development setup, a Compose service might mount a project directory like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
services:
  app:
    image: example-app
    volumes:
      - type: bind
        source: ./src
        target: /app/src
        read_only: true

Read-only access is appropriate when the container only needs to read host content. Omit read_only: true only when the container genuinely needs to modify those files. For production, Docker suggests removing application-code volume bindings when the code should remain inside the image instead of being changeable from outside the container; see Docker’s Compose production guidance.

Watch for missing bind-mount source paths

A typo in a host path can look like a mysterious empty directory inside the container. With Engine CLI usage, --mount normally errors if the source path does not exist, while -v or --volume creates a missing source as a directory. Compose’s short bind syntax also creates a missing source directory for backward compatibility. In Compose long syntax, set create_host_path: false to fail rather than create a directory when the source is absent. The exact options are documented in Docker’s Compose service reference.

Bind mounts also have platform-specific details. Docker documents SELinux z and Z labeling options, but relabeling can affect host files; do not casually apply it to broad system directories. Docker’s Compose service documentation notes that SELinux labeling and ro options are ignored for Compose services in the described context. Check the current behavior for your platform before relying on those options.

Rank #3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

How Docker networks work

A network controls connectivity, not storage. Compose normally creates a project default bridge network and connects the project’s services to it. Services on the same network can discover each other by service name through Docker’s internal DNS, so application configuration should generally use a service name rather than a container IP address. A replacement container can receive a different IP while the service name remains the stable discovery name. See Docker’s Compose networking guide.

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

Use the default project network for a basic stack

For a typical app and database defined in one Compose project, the default network is often enough: both services are attached to it, and the app can address the database by its service name. You do not need to add a custom network solely to make services in that project communicate.

Add custom networks for boundaries or shared connectivity

Custom networks let you choose which services can communicate through a given network. For example, a database can share a network with an application without joining a network used by unrelated services. Multiple Compose projects can communicate through a pre-created external network when their services are attached to it. A service can belong to both a shared network and a project-specific network, enabling cross-project communication while keeping other services on the project-specific side. An internal network has no default gateway for external connectivity. Configuration options are covered in Docker’s Compose network reference.

Rank #4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
  • Easily store and access 4TB of content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

Use host networking only when the host network stack is required

network_mode: host puts a service on the host network stack, changing its exposure boundary. Docker notes that port mapping is unavailable in this mode and service-name DNS resolution does not work. The container can access host ports and traffic, so choose host networking only when that access is genuinely needed.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose storage and connectivity separately

A service can use a storage mount and one or more networks at the same time. Decide each setting by the job it does:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Keep container-generated state across container replacement: use a named volume unless direct host-path sharing is specifically required.
  • Work on host files from inside a development container: use a bind mount, restricting write access to what the container needs.
  • Let services in one Compose project communicate: start with the default project network and service-name discovery.
  • Limit which services can communicate or connect Compose projects: define custom networks and attach only the services that need them.

For example, a database can store its state in a named volume and share a network with the application that uses it. During development, the application can also bind-mount source code. The volume, bind mount, and network address distinct needs.

Best Value
Sale
UnionSine 500GB Ultra Slim Portable External Hard Drive HDD-USB 3.0
  • [Upgraded Version] - This external hard drive features a mirrored logo stripe combined with a striped anti-slip design, and the rounded corners of the casing make it easier to grip. The stripes also have a heat dissipation function, ensuring stable and fast data transfer.
  • 【Ultra-thin and quiet】 - The motherboard adopts JMicron 578 noise-free solution, giving you a quiet working environment. Lightweight and portable size designed to fit in your pocket for easy portability.
  • 【Ultra-Fast Data Transfers】 - Pairing this external hard drive with JMicron 578 solution USB 3.0 and USB 2.0 interfaces enables blazing-fast data transfer. It boasts theoretical read speeds of up to 125MB/s and write speeds of up to 103MB/s.
  • 【Plug and Play】 - With no software to install, just plug it in and the drive is ready to use.The hard disk chip is wrapped with an aluminum anti-interference layer to increase heat dissipation and protect data.
  • 【What You Get】 - 1 x Portable Hard Drive, 1 x USB 3.0 Cable, 1 x User Manual, Gift-type shell packaging ,Three-year manufacturer's warranty and free technical support services.

What happens to data when Compose stops or removes services?

docker compose down removes the project’s containers and networks by default. Named volumes are retained unless you explicitly request their removal; anonymous volume contents are not automatically reused by a later up. Docker recommends explicit bind paths or named volumes for data that must persist between updates. Check the command’s options in the Docker Compose down reference before using a volume-removal option.

Docker provides docker volume prune to remove unused volumes. Since a volume can hold data after its container is gone, inspect what will be removed and confirm that the data is no longer needed before pruning.

Protect host files and review Compose configuration

A bind mount grants a container access to a host path, and a Compose file can contain references that read files available to the user running Compose. Treat unfamiliar Compose files as security-sensitive: inspect their services, mounts, and file references before running them. Docker explains this trust boundary in its Compose file trust model.

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

Documentation behavior can depend on Docker Engine, Compose, and the host platform. Check the references for the version and platform you use, especially when relying on bind-mount creation, SELinux labels, read-only behavior, or networking modes.

Quick Recap

SaleBestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.99
Bestseller No. 2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$229.99
Bestseller No. 3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80
Bestseller No. 4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$208.99

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.