Docker builds Robot Framework environment

Select Alpine Linux for basic image. For the introduction of alpine, see Alpine Docker installation bash . The contents of Dockerfile are as follows:

FROM alpine:3.7

MAINTAINER Rethink shijianzhihu@foxmail.com

RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories

# Add -- virtual will report an error
RUN apk update \
           && apk upgrade \
           && apk add --no-cache bash python python-dev py-pip mysql-dev build-base libffi libffi-dev \
           #&& python -m ensurepip \
           #&& rm -rf /usr/lib/python*/ensurepip \
           && pip --default-timeout=1000 install --upgrade pip setuptools \
                robotframework \
                robotframework-databaselibrary \
                robotframework-requests \
                robotframework-seleniumlibrary \
                robotframework-yamllibrary \
                robotframework-faker \
               # PyMySQL \
          && rm -rf /var/cache/apk/* \
          && rm -rf ~/.cache/* \

ENV PYTHON_VERION 2.7.14

#CMD ["python"]

There are several points to note about the contents of Dockerfile:

  1. The version of Python installed above is 2.7.14. For rf framework, this version is OK. If you want to install 3.x version of python, the apk source of Tsinghua University also provides 3.5.2 version. You only need to change all Python in the Dockerfile content to python3 and pip to pip3;
    Python version in apk source
  2. Only PySQL module is installed above. If you are connecting to other databases, please modify the content by yourself;
  3. In order to enter the container easily, bash is installed for Alpine;
  4. The content of dockerfile is very flexible. You can add CMD and ENTRYPOINT commands for dockerfile according to your actual needs. After combining the two commands, you can more easily execute pybot commands;

Start the container instance for testing, as follows:

[root@JDu4e00u53f7 ~]#  docker run --rm alpine-py27 python --version
Python 2.7.14
[root@JDu4e00u53f7 ~]# docker run  --rm -v /opt/docker/alpine-py/:/alpine-py  alpine-py27 python /alpine-py/hello-world.py
hello world

[To be continue...]

Keywords: Python Docker pip Linux

Added by Drumminxx on Sat, 14 Dec 2019 17:14:37 +0200