我无法在容器内运行 ssh 命令

问题描述 投票:0回答:1

我是 docker 新手,我有如下 dockerfile 来创建 docker 映像。然后我构建图像并运行以下测试命令:

docker run --rm --network host -d -v .:/ansible ansible:latest tail -f /dev/null
docker exec -it c0a5f9c07635 ansible --version
docker exec -it c0a5f9c07635 ansible-playbook test.yaml
docker exec -it c0a5f9c07635 bash

ansible 命令工作正常。但是,当我进入 bash 时,我无法运行 ssh 命令:

root@docker-desktop:/ansible# ssh 8.8.8.8
bash: ssh: command not found

我错过了什么吗?

FROM ubuntu:20.04
USER 0
WORKDIR /ansible
ENV ANSIBLE_VERSION 2.9.17
RUN apt-get update; \
    apt-get install -y gcc python3; \
    apt-get install -y python3-pip; \
    apt-get install -y iputils-ping; \
    apt-get install openssh-client; \
    apt-get clean all
RUN pip3 install --upgrade pip; \
    pip3 install "ansible==${ANSIBLE_VERSION}"; \
    pip3 install ansible
docker ssh ansible containers openssh
1个回答
0
投票

尝试不使用 USER 0 和一些未成年人

FROM ubuntu:20.04
WORKDIR /ansible
ENV ANSIBLE_VERSION 2.9.17

RUN apt update && apt install -y gcc python3 \
    python3-pip \
    iputils-ping \
    openssh-client 

RUN apt-get clean 
# ...

也许你可以使用 ubuntu 22.04 和requirements.txt

## pip Alternative using requirements.txt
COPY requirements.txt .
RUN pip install -r requirements.txt
© www.soinside.com 2019 - 2024. All rights reserved.