我一直在将 ssh-agent 转发到 docker 容器(使用我的 docker-compose 安装)时遇到了严重的麻烦。我有运行 Catalina 的 Mac,使用 docker-engine 19.03.8 和 Compose @ 1.24。以下是我的 docker-compose 文件:
version: '3.7'
services:
platform:
build:
context: .
dockerfile: ./platform/compose/Dockerfile.platform.local
working_dir: /root/platform
ports:
- "3000:3000"
command: ["./compose/scripts/start_rails.sh"]
tty: true
stdin_open: true
volumes:
- type: bind
source: /run/host-services/ssh-auth.sock
target: /run/host-services/ssh-auth.sock
env_file: ./platform/.env
environment:
TERM: xterm-256color
SSH_AUTH_SOCK: /run/host-services/ssh-auth.sock
volumes:
Run Code Online (Sandbox Code Playgroud)
我配置 ssh-agent 转发的方式在docker-compose 文档中指定
该./compose/scripts/start_rails.sh脚本确实bundle install && bundle exec rails s。我从私有存储库中提取的 gem 很少,我认为我应该能够通过转发 ssh-agent 来安装这些 gem。
我还尝试在旋转 docker-compose 之前启动 ssh-agent,但这似乎没有任何作用。 …
目前正在学习 docker 和容器化,我对“moby 运行时”这个术语感到有些困惑。
就我的理解而言,整个 docker 已拆分为多个库/工具/组件,允许开发人员使用 moby 运行时构建自己的 docker 版本。
这个假设正确吗?
如果我使用官方 docker 页面,moby 运行时和例如我在 Windows 机器上下载的桌面 docker 之间究竟有什么关系?
为什么例如 Microsoft 使用 moby 运行时来运行一些服务,例如 IoT Edge 而不是官方的 docker build?他们是否使用他们定制的 docker 版本?
我正在使用谷歌容器注册表来托管我的docker镜像.我也使用moby客户端来golang与之交互.我正在使用JSON服务密钥方法,它似乎与RegistryLogin一起使用.响应文本是Login Successful.但是,我不知道如何使用ImagePull返回的身份验证密钥.在引擎盖设置下,RegistryAuth似乎设置了作为X-Registry-Auth标头传递的任何字符串,谷歌似乎没有在任何地方提到这一点.
我已经尝试将返回的密钥作为RegistryAuth传递,我已经尝试运行RegistryLogin然后只是拉动没有RegistryAuth.我已经尝试了base64编码我的auth配置并在RegistryAuth中发送它.无论我尝试什么,我都会收到"来自守护进程的错误响应:找不到存储库xxx:不存在或没有拉取访问权限".运行docker登录然后使用相同的详细信息进行docker pull在cli上运行正常.我的代码是:
authConfig := types.AuthConfig{
Username: "_json_key",
Password: string(decodedKey),
ServerAddress: "https://gcr.io",
}
_, err = engine.Client.RegistryLogin(ctx, authConfig)
if err != nil {
return err
}
responseBody, err := engine.Client.ImagePull(ctx, image, types.ImagePullOptions{
})
defer responseBody.Close()
if err != nil {
return err
}
Run Code Online (Sandbox Code Playgroud)
decodingKey是JSON密钥文件内容.任何想法如何让这个工作?
我想通过提供 docker-compose.yml文件使用 docker 包从 Golang运行docker-compose项目。
按照https://docs.docker.com/engine/api/sdk/examples/中的示例, 我知道如何使用 Golang 创建和运行单个容器,但是有没有办法从 Golang docker 库运行 docker-compose 项目?
我知道我可以做这样的事情
import "os/exec"
exec.Command("docker-compose","up")
Run Code Online (Sandbox Code Playgroud)
但我希望这件事发生在 docker 包中。
我尝试从容器中给出以下命令,发现下面的问题,可能是因为"-moby"内核版本.我们不能在Linux内核版本中没有"-moby"字样的情况下获得docker镜像.
我尝试在拥有ubuntu的VM上安装linux perf工具,但它确实有效.
#docker run -t -i ubuntu:14.04 /bin/bash
root@214daea94f4f:/# perf
WARNING: perf not found for kernel 4.9.41
You may need to install the following packages for this specific kernel:
linux-tools-4.9.41-moby
linux-cloud-tools-4.9.41-moby
You may also want to install one of the following packages to keep up to date:
linux-tools-moby-lts-<series>
linux-cloud-tools-moby-lts-<series>
Run Code Online (Sandbox Code Playgroud) 所以我有一个非常简单的 Docker Swarm 集群,首先我像这样初始化它:
apt-get update && apt-get upgrade
apt install docker docker-compose
docker stack deploy --prune --compose-file=docker-compose.yml testapp
Run Code Online (Sandbox Code Playgroud)
这是docker-compose.yml文件:
version: "3.7"
services:
db:
image: postgres:10.5-alpine
environment:
- POSTGRES_DB=test_app_production
- POSTGRES_USER=test_app_user
- POSTGRES_PASSWORD=test_app_password
ports:
- "5432:5432"
deploy:
replicas: 1
restart_policy:
condition: "on-failure"
redis:
image: redis:4.0.11-alpine
ports:
- "6379:6379"
deploy:
replicas: 1
restart_policy:
condition: "on-failure"
Run Code Online (Sandbox Code Playgroud)
如何查询 docker DNS 中的 SRV 记录?我知道我可以查询 DNS 并获得循环答案:
ping db
Run Code Online (Sandbox Code Playgroud)
但是我如何告诉集群每个服务有哪些 SRV 记录,以及如何从其他容器查询它们?
我正在尝试使用 docker go 客户端创建一个具有内存限制的容器 - https://godoc.org/github.com/docker/docker/client#Client.ContainerCreate 但是我无法弄清楚在函数中添加这些参数的位置.
docker run -m 250m --name test repo/tag
在 docker api 中,它位于 Host Config 结构下,但在 go doc 中我看到了 HostConfig 中使用的资源下的选项 - https://godoc.org/github.com/docker/docker/api/types/container#HostConfig
像这样打电话
import(
....
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
)
...
resp, err1 := cli.ContainerCreate(ctx,
&container.Config{
User: strconv.Itoa(os.Getuid()), // avoid permission issues
Image: cfg.ImageName,
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Tty: true,
ExposedPorts: exposedPorts,
Labels: labels,
Env: envVars,
},
&container.HostConfig{
Binds: binds,
NetworkMode: container.NetworkMode(cfg.Network),
PortBindings: nat.PortMap{
"1880": []nat.PortBinding{
nat.PortBinding{
HostIP: "",
HostPort: …Run Code Online (Sandbox Code Playgroud) 我有一个 CentOS 7 的 docker 镜像,它通过推荐的说明安装了 docker-ce 。IE
RUN yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
RUN yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
RUN yum update -y
RUN yum install -y docker-ce docker-ce-cli containerd.io
Run Code Online (Sandbox Code Playgroud)
最近这停止工作,现在失败如下:
--> Processing Conflict: moby-containerd-1.3.6+azure-1.x86_64 conflicts containerd
--> Processing Conflict: moby-runc-1.0.0~rc10+azure-2.x86_64 conflicts runc
--> Finished Dependency Resolution
Error: moby-containerd conflicts with containerd.io-1.2.13-3.2.el7.x86_64
Error: moby-runc conflicts with containerd.io-1.2.13-3.2.el7.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles …Run Code Online (Sandbox Code Playgroud) docker ×8
moby ×8
go ×3
containers ×2
linux ×2
azure ×1
centos7 ×1
dns ×1
docker-swarm ×1
dockerfile ×1
perf ×1
runtime ×1
ssh-agent ×1