【问题标题】:How to install python and ansible in windows docker container如何在 windows docker 容器中安装 python 和 ansible
【发布时间】:2019-09-03 10:12:55
【问题描述】:

我的 windows 10 机器上安装了 windows docker。现在我需要在我的 docker 容器中安装 python 和 ansible。

我很少参考在 Linux 机器上安装 python 和 ansible。但我找不到如何在 windows10 docker 容器中安装 python 3 和 ansible 的来源。

一旦安装了 python,我可以尝试使用 pip 命令安装 ansible。但为此,我不确定如何首先安装 python。在 docker 中,我已经安装了 Jenkins,并且想在 Jenkins 中运行我的 ansible 剧本。请帮忙。谢谢!

【问题讨论】:

  • 您可能想参考以下答案:stackoverflow.com/questions/47216784/…。根据答案,您可以在容器中运行以下命令来安装 ansible:RUN sudo pip install ansible。希望这会有所帮助。
  • 我的环境是windows,这个答案中提到的命令不适合我作为Linux环境。
  • 没有运行linux containers on windows?例如你的Dockerfile 是什么样的?
  • 由于 docker 容器设计为在 Windows 中运行,这应该可以解决您的问题。

标签: python windows docker ansible containers


【解决方案1】:

我构建了一个ansible 映像,定期跟踪devel 分支:

# syntax=docker/dockerfile:experimental
FROM ubuntu:18.04

ENV DEBIAN_FRONTEND noninteractive
ENV PATH /ansible/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

RUN apt-get update && \
    apt-get -y install \
        git \
        openssh-client \
        python3.7 \
        python3.7-dev \
        python3-pip \
        python3-setuptools \
        python3-pygit2 \
        build-essential \
        libssl-dev \
        libffi-dev \
        man

RUN groupadd -g 1000 ansible && \
    useradd -u 1000 -g ansible -d /home/ansible -m -k /etc/skel -s /bin/bash ansible

RUN mkdir -p -m 0600 ~/.ssh && \
    ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh git clone -b devel https://github.com/ansible/ansible.git /ansible && \
    chown -R 1000:1000 /ansible

RUN python3 -m pip install -r /ansible/requirements.txt

RUN ln -s /usr/bin/python3 /usr/bin/python

RUN echo '. /ansible/hacking/env-setup' >> /home/ansible/.bashrc
ENTRYPOINT ["/ansible/bin/ansible"]

注意

构建镜像:DOCKER_BUILDKIT=1 docker build --rm --network host -t so:5776957 .

运行容器:docker run --rm --network host -e ANSIBLE_HOME=/ansible -e PYTHONPATH=/ansible/lib so:5776957 localhost -m ping

【讨论】:

  • 在挂载期间遇到此问题“来自守护进程的错误响应:Dockerfile 解析错误第 26 行:未知标志:挂载”。在搜索错误时,我发现“DOCKER_BUILDKIT=1”以 docker build 命令为前缀。但我没有得到确切的解决方案。请提供您的意见。
【解决方案2】:

您可以尝试使用已经安装了相同的现有 docker 映像,而不是自己安装在容器中。如果你还想自己构建,可以查看github repo中的Dockerfile。

https://hub.docker.com/r/zeeshanjamal16/ansibledocker

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-26
    • 2020-12-21
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 2022-09-23
    • 2020-01-12
    • 2018-12-12
    相关资源
    最近更新 更多