问题
Can I run docker command on host? I installed aws
inside my docker container, now can I somehow use aws
command on host (that under the hood will use docker container's aws)?
My situation is like that: I have database backups on production host. now I have Jenkins cron job that will take sql file from db container and take it into server folder. Now I also want jenkins to upload this backup file on AWS storage, but on host I have no aws installed, also I don't want to install anything except docker on my host, so I think aws should be installed inside container.
回答1:
You can't directly do this. Docker containers and images have isolated filesystems, and the host and containers can't directly access each others' filesystems and binaries.
In theory you could write a shell script that wrapped docker run
, name it aws
, and put it in your $PATH
#!/bin/sh
exec docker run --rm -it awscli aws "$@"
but this doesn't scale well, requires you to have root-level permissions on the host, and you won't be able to access files on the host (like ~/.aws/config
) or environment variables (like $AWS_ACCESS_KEY_ID
) with additional setup.
You can just install software on your host instead, and it will work normally. There's no requirement to use Docker for absolutely everything.
来源:https://stackoverflow.com/questions/56206819/run-docker-command-on-host