Docker Community Forums

Share and learn in the Docker community.

How to pack and ship a simple c application in docker without the gcc compiler?

I have a small c program application, i want to build a docker image for that and push it to docker hub and access on any platform.
I want to achieve this within 50MB of image size. i.e. should be able to pack c application and run it without gcc compiler.

Please it will be great help if one can suggest a way to build a image within the size of 50MB. i.e without gcc compiler which is a dependency for c program to compile.

Also suggest which is a best suitable base image for the c application.

NOTE: To build docker image i am using windows as host OS for docker.
NOTE: it is a basic c program to add two number which i want to pack and ship.

Thanks and regards,
Rakesh Chahar

Same question i have.

You can use multi-stage builds.
In the first stage (‘builder’) you install gcc and all the development libraries and compile your program, in the second stage you copy just the files you need to run the program with COPY --from=builder.

1 Like

hello ,
tried the multi-stage build,but i am getting following error on running.

standard_init_linux.go:211: exec user process caused "no such file or directory"

though the executable file is copied successfully and present in the container.

Thanks and Regards,
Rakesh Chahar

This can have 10 different reasons, like wrong path, file not executable…
Comment out the start command, open a shell in the container and try to run it manually.