VOOZH about

URL: https://thenewstack.io/create-a-samba-share-and-use-from-in-a-docker-container/

⇱ Create a Samba Share and Use From in a Docker Container - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2025-03-09 06:00:16
Create a Samba Share and Use From in a Docker Container
tutorial,
Containers / Linux / Networking / Storage

Create a Samba Share and Use From in a Docker Container

How to install Samba and configure it such that it can be used for sharing files to your network from a Linux server.
Mar 9th, 2025 6:00am by Jack Wallen
👁 Featued image for: Create a Samba Share and Use From in a Docker Container
Feature image by Igor Ovsyannykov from Pixabay.
This article has been updated from when it was originally published on July 29, 2023.

Overview

This article provides a step-by-step guide on how to create a Samba share from within a Docker container using Ubuntu Server as the host operating system. The tutorial covers two main topics:

Installing and Configuring Samba on an Ubuntu Server

  • Install Samba with sudo apt-get install samba -y
  • Start and enable the Samba service
  • Set a password for users who will access the share

Creating a Persistent Docker Volume Mapped to the Samba Share:

  • Create a new group and add users to it, setting permissions accordingly
  • Create a persistent Docker volume with docker volume create –opt type=none –opt o=bind –opt device=/data public

Deploying an NGINX Container Using the Docker Volume:

  • Mount the Docker volume to the /usr/share/nginx/html directory in the NGINX container
  • Run a new NGINX instance with docker run -d –name nginx-samba -p 8090:80 -v public:/usr/share/nginx/html nginx

Testing the Setup:

  • Verify that the index.html file is served correctly from the Samba share

The article concludes by noting that this setup may not be suitable for production environments, but it can be useful for development or internal services/apps.

Key Takeaways:

  • Install and configure Samba on an Ubuntu server.
  • Create a persistent Docker volume mapped to a shared directory.
  • Deploy an NGINX container using the Docker volume.
  • Test the setup and verify that files are served correctly from the Samba share.

At some point in either your cloud- or container-development life, you’re going to have to share a folder from the Linux server. You may only have to do this in a dev environment, where you want to be able to share files with other developers on a third-party, cloud-hosted instance of Linux. Or maybe file sharing is part of an app or service you are building.

And because Samba (the Linux application for Windows file sharing) is capable of high availability and scaling, it makes perfect sense that it could be used (by leveraging a bit of creativity) within your business, your app stack, or your services.

You might even want to use a Samba share to house a volume for persistent storage (which I’m going to also show you how). This could be handy if you want to share the responsibilities for, say, updating files for an NGINX-run website that was deployed via Docker.

Even if you’re not using Samba shares for cloud or container development, you’re going to need to know how to install Samba and configure it such that it can be used for sharing files to your network from a Linux server and I’m going to show you how it’s done.

There are a few moving parts here, so pay close attention.

I’m going to assume you already have Docker installed on an Ubuntu server but that’s the only assumption I’ll make.

How To Install Samba on Ubuntu Server

The first thing we have to do is install Samba on Ubuntu Server. Log into your instance and install the software with the command:

sudo apt-get install samba -y

When that installation finishes, start and enable the Samba service with:

sudo sysemctl enable --now smbd

Samba is now installed and running.

You then have to add a password for any user who’ll access the share. Let’s say you have the user Jack. To set Jack’s Samba password, issue the following command:

sudo smbpasswd -a jack

You’ll be prompted to type and verify the password.

Next, enable the user with:

sudo smbpasswd -e jack

How To Configure Your First Samba Share

Okay, let’s assume you want to create your share in the folder /data. First, create that folder with the command:

sudo mkdir /data

In order to give it the proper permissions (so those users who need access), you might want to create a new group and then add users to the group. For example, create a group named editors with the command:

sudo groupadd editors

Now, change the ownership of the /data directory with the command:

sudo chow -R :editors /data

Next, add a specific user to that new group with:

sudo usermod -aG editors USER

Where USER is the specific user name.

Now, make sure the editors group has write permission for the /data directory with:

sudo chmod -R g+w /data

At this point, any member of the editors group should be able to access the Samba share. How they do that will depend on the operating system they use.

How To Create a Persistent Volume Mapped to the Share

For our next trick, we’re going to create a persistent Docker volume (named public) that is mapped to the /data directory. This is done with the following command:

docker volume create --opt type=none --opt o=bind --opt device=/data public

To verify the creation, you can inspect the volume with the command:

docker volume inspect public

The output will look something like this:

[
{
"CreatedAt": "2023-07-27T14:44:52Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/public/_data",
"Name": "public",
"Options": {
"device": "/data",
"o": "bind",
"type": "none"
},
"Scope": "local"
}
]

Let’s now add an index.html file that will be housed in the share and used by our Docker NGINX container. Create the file with:

nano /data/index.html

In that file, paste the following:

Save and close the file.

Deploy the NGINX Container

We can now deploy our NGINX container that will use the index.html file in our public volume that is part of our Samba share. To do that, issue the command:

docker run -d --name nginx-samba -p 8090:80 -v public:/usr/share/nginx/html nginx

Once the container is deployed, point a web browser to http://SERVER:8090 (where SERVER is the IP address of the hosting server), and you should see the index.html file that we created above (Figure 1).

👁 Image

Figure 1: Our custom index.html has been officially served in a Docker container.

Another really cool thing about this setup is that anyone with access to the Samba share can edit the index.html file (even with the container running) to change the page. You don’t even have to stop the container. You could even create a script to automate updates of the file if you like. For this reason, you need to be careful who has access to the share.

Congrats, you’ve just used Docker and Samba together. Although this might not be a wise choice for production environments, for dev or internal services/apps, it could certainly come in handy.

FAQ for Samba Shares

General Questions

  1. What is Samba? Samba is a free, open-source software implementation of the SMB/CIFS protocol, which allows users to access and share files between different operating systems, including Windows, Linux, and macOS.
  2. Why use Samba shares? Samba shares provide a convenient way to share files between devices on your network, making it easy for multiple users to collaborate on projects or access shared resources.

Setting Up Samba Shares

  1. How do I set up a new Samba share? To set up a new Samba share, you’ll need to:
    • Create a directory on your server that will be accessible via the network
    • Edit the /etc/smb.conf file to add a new share definition for the directory
    • Restart the Samba service to apply changes
  2. What permissions should I set up for my Samba shares? You’ll want to set up read-only and read-write permissions as needed, depending on your specific use case.

Accessing and Managing Samba Shares

  1. How do users access a Samba share? Users can access a Samba share using the network path of the share (e.g., \\server\sharename) or by browsing to the shared directory.
  2. Can I set up password protection for my Samba shares? Yes, you can set up password protection for your Samba shares using Kerberos authentication.

Security and Best Practices

  1. How do I secure a Samba share from unauthorized access? To secure a Samba share, use:
    • Strong passwords
    • Limited network connections to the server
    • Encryption (e.g., SSL/TLS)
  2. What are some common security risks associated with Samba shares? Common security risks include:
    • Unauthorized access via weak passwords or default settings
    • Malware transmission through infected files shared over the network

Troubleshooting

  1. Why won’t my Samba share connect to the server? Check that your client is configured correctly and that there are no firewall issues blocking connections.
  2. What if I’m experiencing permission issues accessing a Samba share? Check the permissions set on both the shared directory and any intermediate directories in the path.

Additional Tips

  1. Can I use Samba shares with Docker containers? Yes, you can use Docker volumes to mount external storage for your containers.
  2. How do I integrate my Linux distribution’s native file system features (e.g., fstab) with Samba shares? You’ll need to configure the relevant settings in your /etc/fstab or smb.conf files.

Release Notes

  • Always consult the official Samba documentation for up-to-date information on releases and security patches.
  • Follow best practices to ensure secure sharing of files across your network.
TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
Docker and NGNIX are sponsors of The New Stack.
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.