在ENNTRYPOINT之后,可以在Dockerfile的底部添加什么命令以到达容器提示符? Dockerfile运行正常。只是它可以从执行位置返回到提示。
# Pull base image
From ubuntu:18.04
LABEL maintainer="tester@gmail.com"
# Install dependencies
RUN apt-get update -y
RUN apt-get install -y build-essential python3.6 python3.6-dev python3-pip python3.6-venv
RUN apt-get install -y vim
RUN python3.6 -m pip install pip --upgrade
RUN pip3 install pytest pytest-cache
RUN pip3 install pylint
RUN pip3 install requests
# Create working directory
RUN mkdir /testsuite
# Copy project
COPY comments_categories_api /testsuite/comments_categories_api
COPY comments_posts_api /testsuite/comments_posts_api/
RUN chmod -R a+rwX testsuite/
# Set working directory
WORKDIR /testsuite
# Set Python version
RUN echo alias python='/usr/bin/python3' >> ~/.bashrc
# RUN echo cd testsuite/ >> ~/.bashrc
# Define ENTRYPOINT
COPY ./docker-entrypoint.sh /testsuite/docker-entrypoint.sh
RUN ["chmod", "+x", "/testsuite/docker-entrypoint.sh"]
ENTRYPOINT ["sh", "/testsuite/docker-entrypoint.sh"]
答案 0 :(得分:1)
以“ $ @”结束您的docker-entrypoint.sh。这是一个示例:
#!/bin/bash
echo Hello
$@
===更新
根据您的评论,文件应为:
#!/bin/bash
pytest -v
$@
答案 1 :(得分:1)
进入ENTRYPOINT之后,容器将退出。
这听起来像是在说您想要一个首先运行测试然后启动交互式外壳的容器。您需要制作一个可以执行此操作的Shell脚本
#!/bin/sh
pytest -v
sh
然后使该脚本成为图像的主要过程。
我在这里有两种风格的评论,阅读其他评论也可能对您很重要。您提到尝试使用
运行交互式shelldocker run -it vip_app:v0.1 /bin/bash
如果使用CMD声明process命令,那么您的/bin/bash
命令将替换CMD,您将获得一个交互式shell。如果使用ENTRYPOINT声明它,则/bin/bash
作为参数传递给ENTRYPOINT(并且可能会被完全忽略)。如果我不太需要两者,我倾向于CMD而不是ENTRYPOINT。
您还尝试使用python
文件更改默认的.bashrc
命令。在许多常见情况下,.bashrc
不会被阅读。例如,如果您
docker run --rm vip_app:v0.1 python myapp.py
.bashrc
将不会被读取,您将运行/usr/bin/python
(可能是Python 2.7)。我只是根本不会在图像中安装类似“便利”的东西。