build context for docker image very large

后端 未结 10 874

I have created a couple different directories on my host machine as I try to learn about Docker just to keep my dockerfiles organized. My Dockerfile I just ran looks like t

相关标签:
10条回答
  • 2020-12-12 13:01

    I had the same issue as FreeStyler. However I was building from a directory one up from my context. So the -f arguments were correct the context was incorrect.

    project 
    |
    -------docker-dir 
    

    Building from the docker-dir the following was fine

    docker build -t br_base:0.1 . 
    

    Building from the dock-dir the the build context changed. Therefore I needed to change the context in the command. Context is given by the '.' in the command above.

    The the new command from the project directory should be

    docker build -t br_base:0.1 ./base
    

    Context here is given by the './base'

    0 讨论(0)
  • 2020-12-12 13:03

    In my case that was when i execute with wrong -f arguments - without path to directory where located Dockerfile

    docker build --no-cache -t nginx5 -f /home/DF/Dockerfile /home/DF/ - right

    docker build --no-cache -t nginx5 -f /home/DF/Dockerfile - wrong

    0 讨论(0)
  • 2020-12-12 13:03

    For NodeJS Application, add a .dockerignore file your root project directory and inside the .dockerignore file add the following

    node_modules
    dist
    
    0 讨论(0)
  • 2020-12-12 13:06

    Just to summarize what you can do if your Docker image build context too large:

    • make sure you don't have unused files in the context (unused files - those that still untouchable during image building);
    • add unused files and/or directories to .dockerignore (as mentioned here);
    • make sure you specify the right folder as an image build context (as mentioned here);
    • try to use BuildKit with DOCKER_BUILDKIT=1 (as mentioned here);
    • try to split your project into smaller parts to optimize content of build context;
    • if you have a complex project you may want to manually collect all necessary files in separate folder before build and use it as a build context for a specific image.
    0 讨论(0)
提交回复
热议问题