# Docker image with two different python versions

**URL:** <https://forums.docker.com/t/docker-image-with-two-different-python-versions/139998>\
**Category:** Docker Desktop\
**Tags:** docker, build, macos\
**Created:** [February 22, 2024, 2:32pm UTC](https://forums.docker.com/t/docker-image-with-two-different-python-versions/139998 "2024-02-22T14:32:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![freshairmanoj](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@freshairmanoj](https://forums.docker.com/u/freshairmanoj)\
**Post date:** [February 22, 2024, 2:32pm UTC](https://forums.docker.com/t/docker-image-with-two-different-python-versions/139998/1 "2024-02-22T14:32:58Z")

</div>

Hello Community,

FROM public.ecr.aws/lambda/python:3.8

#### check our python environment

RUN python --version  
RUN pip --version

#### Copy function code

COPY requirements/requirements-prod.txt ${LAMBDA\_TASK\_ROOT}/requirements.txt  
COPY src/handler.py ${LAMBDA\_TASK\_ROOT}/handler.py  
COPY src/ ${LAMBDA\_TASK\_ROOT}/src

RUN python3.8 -m pip install -r requirements.txt --target “${LAMBDA\_TASK\_ROOT}”

#### Set the CMD to your handler

CMD [“handler.profile”]

#### Question

I have been using the above template to build docker images and deploy on AWS Lambda. This template is working for me, but now I would like to deploy different versions of python (ex: python 3.8 and python 3.11.5) and different versions of requirements.txt files for each of the python versions mentioned above.

Is it possible to build two different versions using same Dockerfile? If yes how can I format the Dockerfile to reflect the same?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [February 22, 2024, 9:25pm UTC](https://forums.docker.com/t/docker-image-with-two-different-python-versions/139998/2 "2024-02-22T21:25:57Z")

</div>

> [@freshairmanoj](#):
>
> Is it possible to build two different versions using same Dockerfile?

You can use build arguments to specify the python version

[https://docs.docker.com/reference/dockerfile/#arg](https://docs.docker.com/reference/dockerfile/#arg)

and place your different files in different folders containing the python version like:

```auto
./files/common/
./files/python-3.8/
./files/python-3.5/

```

Example:

```auto
ARG PYTHON_VERSION
FROM public.ecr.aws/lambda/python:${PYTHON_VERSION}
ARG PYTHON_VERSION

COPY ./files/common/ /files/
COPY ./files/python-${PYTHON_VERSION}/ /files/

RUN python${PYTHON_VERSION} ....

```

```auto
docker build . --build-arg PYTHON_VERSION=3.8 -t tag

```

ARG must be defined before and after FROM so you can use it in the FROM instruction and also after it.
