question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker: How to setup production container to be smaller?

See original GitHub issue

Hello, i am using old version of react-starter kit intl with old tools(build,run etc) before update of webpack, my webpack is (1.13.3) i am new with this, is there any way to build all node_modules that needed in single file while doing

npm run build – --release and then just build docker container without

RUN npm install yarn --global --no-progress --silent --depth 0 && \
    yarn install --production --no-progress

? My build folder is 5ΜΒ. But Docker Container become 500mb Sorry for the inconvenience

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fhillipgcastillocommented, Aug 11, 2020

Hello,

I hope to bring a solution as is been too long time and this is open. I found this as I looking for best practices and improvements in my learning curve about Docker.

Intro to the solution

Docker has the ability to use the multi-stage build for the containerization process and we can also name them to be reutilized certain things from the other stages.

What is Multi-Stage Builds

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image. To show how this works, let’s adapt the Dockerfile from the previous section to use multi-stage builds. [Taken from docker documentation]

An example:

FROM golang:1.7.3 AS builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html  
COPY app.go    .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]  
...

Also found at Docker multi-stage builds documentation

I hope this all gives you the solution you where looking for, @Shadowman4205 and the others.

Read the full documentation for Multi-stage Builds

I found this from dockerfile best practices

0reactions
ulanicommented, May 27, 2021

@Shadowman4205 thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion.

NOTE: The main branch has been updated with React Starter Kit v2, using JAM-style architecture.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Reduce Docker Image Size: 5 Optimization Methods
Method 3: Minimize the Number of Layers​​ Docker images work in the following way – each RUN, COPY, FROM Dockerfile instructions add a...
Read more >
3 simple tricks for smaller Docker images - Learnk8s
1. Squash multiple layers into one with multi-stage Docker builds · 2. Remove all the unnecessary cruft from the container with distroless ·...
Read more >
How to make smaller Docker containers (including multi-stage ...
If not careful, containers can become much larger than necessary which makes them annoying to download/upload from/to a container registry.
Read more >
How to Reduce Docker Image Size in Docker Containers
The following sections cover three methods to make your Docker image size smaller. Method 1: Applying Multi-Stage Builds. Having separate ...
Read more >
BEST PRACTICES TO REDUCE DOCKER IMAGES SIZE
Best Practices to Reduce Docker Images Size · 1. USE A SMALLER BASE IMAGE · 2. DON'T INSTALL DEBUG TOOLS LIKE curl/vim/nano ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found