我有一个在docker上创建sftp镜像的docker-compose yml。我想在yml文件中编写脚本,因为我希望在运行docker-compose.yml后立即自动创建目录。
这是我的yml文件;
sftp:
image: atmoz/sftp
volumes:
- C:\tmp\sftp:/home/foo/upload
ports:
- "2222:22"
command: username:password:1001
有没有办法在此文件中写入
mkdir
和chmod
?
最佳答案
您不需要手动创建和设置mod,只需将目录名称传递给CMD
,入口点将为您创建一个。这是最简单的例子。
Define users in (1)
command arguments
, (2)SFTP_USERS
environment variable or (3) in file mounted as/etc/sftp/users.conf
(syntax:user:pass[:e][:uid[:gid[:dir1[,dir2]...]]] ...
, see below for examples)
使用docker-compose
sftp:
image: atmoz/sftp
command: username:password:100:100:upload
它将创建用户名
username
和目录在/home/username
下上传您可以使用
docker exec -it --user username <container_id> bash -c "ls /home/username"
如果您想从主机访问上传文件,只需在docker-compose中添加挂载
sftp:
image: atmoz/sftp
command: username:password:100:100:upload
volumes:
- /host/upload:/home/username/upload
示例
最简单的Docker运行示例
docker run -p 22:22 -d atmoz/sftp foo:pass:::upload
User "foo" with password "pass" can login with sftp and upload files to a folder called "upload". No mounted directories or custom UID/GID. Later you can inspect the files and use --volumes-from to mount them somewhere else (or see next example).
看到offical documentation
关于docker - 在docker-compose.yml文件中创建目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58742949/