skip to Main Content

this is my docker file:

WORKDIR /scan

RUN pip install pymongo
RUN pip install netmiko
RUN pip install pyats[full]
ENV Testbed=
ENV arr=
# ENV device=
# ENV id=

COPY . /scan
ENTRYPOINT ["python3", "main.py"]

I want to pip install this particular packages locally Like from a tar files. I want to build the image without any internet, so that’s why I need it to be locally so that the pip will take them from local and not from internet.
I just want to clarify that when I pip install requirements it will go anyway to the internet, I already try it.

2

Answers


  1. You need base image in dockerfiles:

    # Set the base image
    FROM python:3.8
    
    # Set the working directory
    WORKDIR /scan
    
    # Copy the local tar files into the image
    COPY your_package1.tar.gz your_package2.tar.gz /tmp/
    
    # Install packages from local tar files
    RUN pip install /tmp/your_package1.tar.gz && 
        pip install /tmp/your_package2.tar.gz
    
    # Set environment variables if needed
    ENV Testbed=
    ENV arr=
    
    # Copy the rest of your application files
    COPY . /scan
    
    # Specify the entry point
    ENTRYPOINT ["python3", "main.py"]
    

    For running any commands in the process of building docker image (keyword RUN):

    # Install system packages using apt-get
    RUN apt-get update && 
        apt-get install -y openssh-server apache2 supervisor
    
    Login or Signup to reply.
  2. Build you docker images from a internet PC:

    docker build –t myimage:0.1 .
    

    Save the built image:

    docker save -o <path for generated tar file> <image name>
    

    In you case:

    docker save -o c:/myimage_0-1.tar myimage:0.1
    

    Then copy your image to a new system (which has no internet access) with regular file transfer tools such as cp, scp, or rsync (preferred for big files). After that you will have to load the image into Docker:

    docker load -i <path to image tar file>
    

    Then you can use the run command to start the image.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search