How to rebuild dockerfile quick by using cache?

后端 未结 3 1049
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 01:59

I want to optimize my Dockerfile. And I wish to keep cache file in disk. But, I found when I run docker build . It always try to get every file from network.

<
3条回答
  •  春和景丽
    2021-02-02 02:14

    An update to previous answers, current docker build accepts --build-arg that pass environment variables like http_proxy without saving it in the resulting image.

    Example:

    # get squid
    docker run --name squid -d --restart=always \
      --publish 3128:3128 \
      --volume /var/spool/squid3 \
      sameersbn/squid:3.3.8-11
    
    # optionally in another terminal run tail on logs
    docker exec -it squid tail -f /var/log/squid3/access.log
    
    # get squid ip to use in docker build
    SQUID_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' squid)
    
    # build your instance
    docker build --build-arg http_proxy=http://$SQUID_IP:3128 .
    

提交回复
热议问题