Dockerfile
#Source images
FROM centos:6
#Author
MAINTAINER shark1985
#Repo
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && yum makecache
#Install
RUN yum -y install samba
#Port
EXPOSE 139 445
#Service
CMD ["/usr/sbin/smbd","-FS"]
构建镜像
docker build -t smb-c6 .
Sending build context to Docker daemon 4.608kB
Step 1/6 : FROM centos:6
---> d0957ffdf8a2
Step 2/6 : MAINTAINER shark1985
---> Running in 9f655a57369a
Removing intermediate container 9f655a57369a
---> e2208fe6475c
Step 3/6 : RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && yum makecache
---> Running in 52a9f11e888e
Removing intermediate container 52a9f11e888e
---> bbdd605a17d5
Step 4/6 : RUN yum -y install samba
---> Running in c22efab210f4
Removing intermediate container c22efab210f4
---> c1570c047f21
Step 5/6 : EXPOSE 139 445
---> Running in 89586c691a19
Removing intermediate container 89586c691a19
---> f7e41a3fc7e8
Step 6/6 : CMD ["/usr/sbin/smbd","-FS"]
---> Running in e6ada57d282f
Removing intermediate container e6ada57d282f
---> 5b1553888b4e
Successfully built 5b1553888b4e
Successfully tagged smb-c6:latest
运行容器
docker run -d -p 139:139 -p 445:445 smb-c6:latest
查看容器
docker ps -a |grep smb
2a039d489b71 smb-c6:latest "/usr/sbin/smbd -FS" 33 minutes ago Up 33 minutes 0.0.0.0:139->139/tcp, 0.0.0.0:445->445/tcp confident_clarke
匿名登录测试
smbclient -L 10.x.x.x
WARNING: The "syslog" option is deprecated
Enter WORKGROUP\admin's password:
Anonymous login successful
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba Server Version 3.6.23-51.el6)
Reconnecting with SMB1 for workgroup listing.
Anonymous login successful
Server Comment
--------- -------
Workgroup Master
--------- -------
其他补充
- 共享服务没有进行具体配置,如无共享目录和账号认证
- 在dockerfile中指定volume,可让共享目录对应本机挂载的存储目录上
- 可不做文件共享,搭配CUPS提供共享打印机服务