Last active
May 19, 2020 06:13
-
-
Save julesghub/d03c4249ec0c7257c168d16e42c419ff to your computer and use it in GitHub Desktop.
debug dockerfile with build-args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Build this images on top of the `ubuntu:20.04` docker image. | |
### Docker searches for ubuntu:20.04 on the hub.docker | |
FROM ubuntu:20.04 | |
### use ubuntu's package manager system `apt-get` to install compilers | |
RUN apt-get update -qq && \ | |
apt-get install -yq gcc | |
### add anyother packages you want above | |
ARG WITH_DEBUG | |
#copy file into docker | |
COPY test.c . | |
RUN if [ -z ${WITH_DEBUG+x} ]; then \ | |
export CFLAGS="-O3" ; \ | |
else \ | |
apt-get install -yq gdb ; \ | |
export CFLAGS="-g -O0" ; \ | |
fi && \ | |
echo ${CFLAGS} && \ | |
gcc ${CFLAGS} -o test test.c | |
CMD ./test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() { | |
int x; | |
char string[]="Hello world"; | |
for(x=0; x<3; x++) { | |
printf("%d...",x); | |
} | |
printf("%s\n", string); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment