我希望用户可以通过 ssh 访问容器。或者更准确地说:主机用户可以访问容器化的 shell。这可能看起来很奇怪,但它确实有效:
$ cat /etc/passwd | grep staging
staging:x:1001:1001::/home/staging:/usr/local/bin/stagingclish
$ groups staging
staging : staging docker
$ cat /usr/local/bin/stagingclish
#!/bin/sh
cd /home/cloud/docker/myproject-staging && docker-compose run --rm --entrypoint=bash php-cli $@
php-cli
只是从 php:7.4-cli 镜像自定义构建的,包括一些实用程序,如 rsync。此外,/etc/passwd 是从主机挂载的。
我可以用 登录ssh staging@myhost
。
我可以调用命令:
ssh staging@myhost ls /
Creating myproject-staging_php-cli_run ...
Creating myproject-staging_php-cli_run ... done
CHANGELOG.md
COPYING.txt
Gruntfile.js.sample
...
现在我希望能够使用scp
和rsync
命令从容器中检索/上传文件。
但:
scp staging@myhost:/var/www/repo/auth.json.sample .
Creating myproject-staging_php-cli_run ...
Creating myproject-staging_php-cli_run ... done
usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program] source ... target
1
和
rsync staging@myhost:/var/www/repo/auth.json.sample .
[... rsync help ...]
rsync error: syntax or usage error (code 1) at main.c(1580) [client=3.1.3]
1
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(228) [Receiver=3.2.3]
我甚至不知道这是否可行。有人能解释一下吗?