Skip to content

Instantly share code, notes, and snippets.

@julesghub
Last active May 19, 2020 06:13
Show Gist options
  • Save julesghub/d03c4249ec0c7257c168d16e42c419ff to your computer and use it in GitHub Desktop.
Save julesghub/d03c4249ec0c7257c168d16e42c419ff to your computer and use it in GitHub Desktop.
debug dockerfile with build-args
### 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
#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