python - 如何在Windows docker容器中安装python和ansible

标签 python windows docker ansible containers

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

我很少有关于在 Linux 机器上安装 python 和 ansible 的引用。但我找不到如何在 windows10 docker 容器中安装 python 3 和 ansible 的源代码。

安装 python 后,我可以尝试使用 pip 命令安装 ansible。但为此我不知道如何首先开始安装 python。在 docker 中,我已经安装了 Jenkins,并且想在 Jenkins 中运行我的 ansible playbook。请帮忙。谢谢!

最佳答案

我构建了一个 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

enter image description here

关于python - 如何在Windows docker容器中安装python和ansible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57769572/

相关文章:

python - Pandas 数据帧 : assign to different columns based on positive/negative values

python - 我应该如何在我的模板之间共享代码 ("modules")?

.net - 视觉基础 : restarting Desktop Windows Manager (DWM)

Docker + Kubernetes 构建

docker - 在Kubernetes从站中运行的无根Did, 'docker run'失败

java - 从在 docker 容器中运行的 JVM 应用程序将日志发送到 graylog 的最佳做法是什么?

使用属性装饰器的 Python 只读列表

python - 你能在 Python 中创建多个 "if"条件吗?

windows - 如何在 Windows 上获取 rsync 命令?

windows - 在 Windows 安装项目中注册和注销 DLL