docker-compose 下部署smb共享
时间: 2023-08-17 10:26:42 浏览: 59
要在 Docker Compose 中部署 SMB 共享,您可以使用以下步骤:
1. 创建一个 Dockerfile,其中包含安装 Samba 的命令。例如:
```Dockerfile
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y samba
COPY smb.conf /etc/samba/smb.conf
CMD ["smbd", "--foreground", "--no-process-group"]
```
这个 Dockerfile 安装了 Samba 软件,并将 smb.conf 文件复制到容器中。
2. 创建一个 smb.conf 文件,其中包含共享的配置信息。例如:
```
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = smbserver
security = user
map to guest = bad user
dns proxy = no
[share]
comment = Shared Folder
path = /share
read only = no
guest ok = yes
```
这个文件定义了一个名为 share 的共享文件夹,它指向容器中的 /share 目录。
3. 创建一个 docker-compose.yml 文件,定义服务的配置信息。例如:
```yaml
version: "3"
services:
smb:
build: .
ports:
- "139:139"
- "445:445"
volumes:
- ./data:/share
restart: always
```
这个文件定义了一个名为 smb 的服务,它使用上面创建的 Dockerfile 构建镜像。它将主机的 139 和 445 端口映射到容器中的端口,并将主机上的 ./data 目录挂载到容器中的 /share 目录。restart: always 表示容器停止后会自动重启。
4. 运行 docker-compose 命令启动服务:
```
docker-compose up -d
```
这个命令会启动一个名为 smb 的容器,它会自动加载 smb.conf 文件并启动 Samba 服务。您可以使用 smb://localhost/share 访问共享文件夹。
希望这些步骤能帮助您在 Docker Compose 中部署 SMB 共享。