在主机上运行docker命令 [英] Run docker command on host

查看:98
本文介绍了在主机上运行docker命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在主机上运行docker命令吗?我在docker容器中安装了 aws ,现在我可以以某种方式在主机上使用 aws 命令(引擎盖下将使用

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)?

我的情况是这样的:我在生产主机上有数据库备份。现在我有Jenkins cron作业,它将从db容器中获取sql文件,并将其放入服务器文件夹中。现在,我还希望jenkins将此备份文件上传到AWS存储上,但是在主机上我没有安装aws,也不想在主机上安装除docker以外的任何东西,因此我认为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.

推荐答案

您不能直接执行此操作。 Docker容器和映像具有隔离的文件系统,并且主机和容器不能直接访问彼此的文件系统和二进制文件。

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.

从理论上讲,您可以编写一个封装了shell脚本 docker run ,将其命名为 aws ,并将其放入您的 $ PATH

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 "$@"

但这不能很好地扩展,需要您对主机具有root级权限,并且您将无法访问主机上的文件(例如〜/ .aws / config )或环境变量(例如 $ AWS_ACCESS_KEY_ID ),并进行其他设置。

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.

您可以直接在主机上安装软件,即可正常运行。不需要绝对使用Docker。

You can just install software on your host instead, and it will work normally. There's no requirement to use Docker for absolutely everything.

这篇关于在主机上运行docker命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆