Home > Software > Setting Up a Samba File Server with Docker Compose: A Step-by-Step Guide

Setting Up a Samba File Server with Docker Compose: A Step-by-Step Guide

Anastasios Antoniadis

Discover how to deploy a Samba file server efficiently using Docker Compose with our step-by-step guide. This article provides an example configuration to streamline your Samba server setup, ensuring a consistent and isolated file sharing environment across your network.

Docker (1)

Samba is a popular open-source software suite that provides seamless file and print services to SMB/CIFS clients. It allows Windows clients to access files and printers hosted on Unix and Linux servers as if they were native resources. With its containerization technology, Docker offers a streamlined way to deploy Samba servers, ensuring consistency across different environments and simplifying the configuration process. This article provides a practical guide to deploying a Samba server using Docker Compose, including an example Docker Compose file to get you started.


Before you begin, your machine should have Docker and Docker Compose installed. Knowledge of basic Docker commands and familiarity with Docker Compose will also be helpful.

Docker Compose Configuration for Samba

The docker-compose.yml file is the heart of deploying services with Docker Compose, which defines your application’s services, networks, and volumes. Below is an example configuration for setting up a Samba file server using Docker Compose.

Step 1: Create the Docker Compose File

Create a file named docker-compose.yml in your project directory and open it in a text editor. Add the following content to define the Samba service:

version: '3.7'

    image: dperson/samba
    container_name: samba_server
    restart: unless-stopped
      - sambanet
      - /path/to/shared/folder:/mount
      - /path/to/samba/config:/etc/samba
      - "139:139"
      - "445:445"
    command: ['-u "exampleUser;examplePass"', '-s "Public;/mount;yes;no;yes;all;none;Public"', '-p']
      - TZ=Europe/London

    driver: bridge


In this configuration:

  • image: dperson/samba specifies the Docker image to use for the Samba server. The dperson/samba image is a popular choice for running Samba in Docker.
  • container_name sets a custom name for your Samba container.
  • restart: unless-stopped ensures the container restarts automatically unless explicitly stopped.
  • The volumes section mounts directories from the host into the container. Replace /path/to/shared/folder with the path to the folder you want to share via Samba, and /path/to/samba/config with the path to your Samba configuration files (optional).
  • ports maps the Samba ports from the container to the host, allowing access to the Samba server from other machines.
  • The command section includes Samba parameters for user creation (-u), share definition (-s), and enabling the Samba server to run in the foreground (-p).
  • environment allows you to set environment variables, such as the timezone (TZ).

Step 2: Running Your Samba Server

With your docker-compose.yml file created, you can start the Samba server by navigating to the directory containing the file and running:

docker compose up -d

This command starts the Samba server in detached mode, allowing it to run in the background.

Step 3: Accessing the Samba Share

Once the Samba server is running, you can access the shared folder from a Windows client by entering \\<your_server_ip>\Public in the File Explorer address bar, replacing <your_server_ip> with the IP address of your Docker host. On Linux, you can access the share using a Samba client with a similar URL.


Deploying a Samba file server with Docker Compose offers a flexible and efficient way to share files across your network, leveraging the benefits of containerization to ensure a consistent and isolated environment. By customizing the example docker-compose.yml file to fit your specific requirements, you can easily set up and manage a Samba server, simplifying file sharing between Windows and Unix/Linux systems. Docker Compose not only streamlines the deployment process but also makes it easier to manage and scale your Samba server as needed.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x