How can I create an image on Docker but instead use copy for the files use git clone

Asked

Viewed 31 times

0

I have a repository on github with my project and I need to create an image to run this project but I’m not getting

FROM python:3.6.7
MAINTAINER RENAN SACCA
CMD ["git","clone","https://github.com/Renan-Sacca/teste-docker.git"]
WORKDIR teste-docker
RUN pip3 install -r requirements.txt
EXPOSE 8000
CMD ["python3", "main.py"]

He error when installing the requirement says he didn’t find it so I think the problem is getting git directory

1 answer

0


The mistake is in the confusion between CMD and RUN.

According to Docker’s documentation, the instruction CMD serves primarily to indicate the parameters to be used by the entrypoint of a container. And adds that Dockerfile must contain a SINGLE instruction CMD and if more than one is added, only the last will have effect.

This is precisely the problem of your Dockerfile. First, even if CMD ["git","clone","https://github.com/Renan-Sacca/teste-docker.git"] were correct, it would be ignored because there is another CMD. Although there was no other CMD is used only at the time of container startup. That’s why when making RUN pip3 install -r requirements.txt there is no requirements.txt.

To execute instructions in the build of an image you must use the RUN. That way, your Dockerfile should be something like

FROM python:3.6.7
LABEL maintainer="RENAN SACCA"
EXPOSE 8000

RUN git clone https://github.com/Renan-Sacca/teste-docker.git
WORKDIR teste-docker
RUN pip3 install -r requirements.txt

CMD ["python3", "main.py"]

Obs:

  • the instruction MAINTAINER is obsolete and has been replaced by LABEL;
  • the instruction EXPOSE was moved to improve the readability of the code;
  • I get it, I’m learning middle of zero so I didn’t know this from cmd, I tested the code that left and worked, thank you very much for the help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.