Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using docker --squash in docker-compose when building images

Is there a way to use the --squash option in docker-compose when building new docker images? Right now they have implemented --squash in docker as of 6 months ago, but I have not seen any docs about how to use this in docker-compose.yml.

Is there a work around here? (I see an open issue filed requesting this feature)

like image 298
ibaralf Avatar asked Jul 21 '17 14:07

ibaralf


People also ask

Can you build images using docker compose?

From your project directory, start up your application by running docker compose up . Compose pulls a Redis image, builds an image for your code, and starts the services you defined. In this case, the code is statically copied into the image at build time.

Do you need Dockerfiles with docker compose?

Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.

Does Docker squash reduce image size?

Used Docker Squash to reduce the size of the final image. This is effective if your image has multiple layers created using RUN clause. The Squash attempts to create a single layer out of all the layers and thus reduced the overall size. I did get the size down up to ~12% for a few images.

Does docker compose rebuild images?

If the container requires to build an image, the run command also builds the container but it doesn't have to rebuild the image. docker run does not build either. docker-compose up does everything so you have the option to rebuild.


1 Answers

You can achieve squash result with trick like

FROM oracle AS needs-squashing
ENV NEEDED_VAR some_value
COPY ./giant.zip ./somewhere/giant.zip
RUN echo "install giant in zip"
RUN rm ./somewhere/giant.zip

FROM scratch
COPY --from=needs-squashing / /
like image 122
Ryabchenko Alexander Avatar answered Sep 20 '22 13:09

Ryabchenko Alexander