简体   繁体   English

如何在 AspNetCore 网站 Docker-Container 中使用 Docker 命令?

[英]How to use Docker commands inside AspNetCore Website Docker-Container?

I'm trying to build a docker image inside an as.netcore docker container.我正在尝试在 as.netcore docker 容器中构建一个 docker 图像。 The as.netcore container is a website which collects data from different sources and then dynamically builds a dockerfile. Afterwards I want to create a docker image from the dockerfile inside this as.netcore application. as.netcore 容器是一个从不同来源收集数据然后动态构建 dockerfile 的网站。之后我想从这个 as.netcore 应用程序中的 dockerfile 创建一个 docker 图像。

I tried to mount the docker socket in different ways but I cannot use the docker commands inside my container.我尝试以不同的方式安装 docker 套接字,但我无法在容器内使用 docker 命令。

I refered to the following link: http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/我参考了以下链接: http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

so i tried to run the image and mount the docker socket in following ways:所以我尝试运行图像并通过以下方式安装 docker 套接字:

directly in the cmd:直接在cmd:

docker run -v /var/run/docker.sock:/var/run/docker.sock webinterface

inside my docker-compose file:在我的 docker-compose 文件中:

services:
  webinterface:
    image: webinterface
    container_name: webinterface
    build:
      context: ./WebInterface
      dockerfile: Dockerfile
  external_links:
    - geonode_geonode_1
  ports:
    - "5000:80"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock

and then I tried to use the docker commands inside the container with:然后我尝试在容器内使用 docker 命令:

docker exec -it webinterface bash

but the webinterface does not recognize any docker commands:但网络界面无法识别任何 docker 命令:

root@f3e434254601:/app# docker help
bash: docker: command not found

I also tried to use the docker remote API to execute commands by installing the nuget package "Docker.DotNet" and connect to the docker host as described in the offical documentation:我还尝试使用 docker 远程 API 通过安装 nuget package “Docker.DotNet” 并连接到 docker 主机来执行命令,如官方文档所述:

            DockerClient client2 = new DockerClientConfiguration(new Uri("npipe:////./pipe/docker_engine"))
            .CreateClient();

        return await client2.Containers.ListContainersAsync(
            new ContainersListParameters()
            {
                Limit = 10,
            });

I'm totally lost... Does anyone have an idea?我完全迷路了......有人有想法吗? thank you!谢谢你!

If you want to execute docker commands you will still need to install docker.io in your container (here called "webinterface").如果你想执行 docker 命令,你仍然需要在你的容器中安装docker.io (这里称为“webinterface”)。

Add this to the Dockerfile of your container-image.将其添加到容器映像的 Dockerfile。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM