1

There is a dockerfile that we are using to configure python version X. The dockerfile is being used in circle ci to build the image and then push to gcr. I want to create another image of python version Y. The question is should i put in the same dockerfile or a separate dockerfile.

If its in same dockerfile then how would i trigger different builds? I am looking at this answer, the think which is confusing me that i can tag the image at first line i.e., FROM gcr.io/google-appengine/python:2019-08-07-184603 as python2.7, how would i make sure that certain commands to build this image are ran against it and then other commands ran against python3.7 image.

P.S: Would prefer if i don't have to use docker-compse.

Christian Vorhemus
  • 2,396
  • 1
  • 17
  • 29
Em Ae
  • 8,167
  • 27
  • 95
  • 162

2 Answers2

0

Here an example that how you can

FROM gcr.io/google-appengine/python:2019-08-07-184603 as python2.7

RUN echo "python2.7"


FROM python:3.9.2-slim as anotherpython

RUN echo "anotherpython"

For create python2.7;

docker build -t tag --target python2.7 .

For create another python version;

docker build -t tag --target anotherpython .
Mustafa Güler
  • 884
  • 6
  • 11
0

From what I understand, you want to create two different images (one with python2.7 and one with 3.7) but the rest of the Dockerfile is basically the same. You then want to use those images for different stages of your CI/CD pipeline.

You should create two different Dockerfile, as you are creating two different images. One will be an image based on python2.7, the other on python3.7 When you create those images (docker build command), you should use the -t option to tag those images with the name you want to give them. You can then push those images to gcr and use them in yourCI/CD stage by using their names.

Faeeria
  • 786
  • 2
  • 13