FROM centos:7
RUN yum -y install httpd
ADD index.html /var/www/html/index.html
ENV A 100
ENTRYPOINT ["/usr/sbin/httpd"]
CMD ["-D", "FOREGROUND"]
EXPOSE 80
VOLUME /var/www/html
docker build -t <IMAGE>:<TAG> .
docker run --entrypoint <ENTRYPOINT> <IMAGE> <CMD>
Shell 형식
CMD ls -l
Exec 형식(*)
CMD ['ls', '-l']
Exec 형식에서 Shell을 사용해야 하는 경우(*)
CMD ['/bin/sh', '-c', 'ls', '-l']
주의: exec 형식인 경우 실행 파일을 절대 경로로 표현!
예) ENTRYPOINT , CMD 같이 사용하는 예
ENTRYPOINT python3 /django-helloworld/helloworld/manage.py runserver
CMD 0.0.0.0:8000
docker run -d xyz 0.0.0.0:5000
단순 유예
ENV DEBIAN_FRONTEND=noninteractive
Timezone 설정
RUN DEBIAN_FRONTEND=noninteractive apt install tzdata
ENV TZ Asia/Seoul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN dpkg-reconfigure --frontend noninteractive tzdata
FROM ubuntu:focal
RUN apt update
RUN DEBIAN_FRONTEND=noninteractive apt install tzdata
ENV TZ Asia/Seoul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localyime && echo $TZ > /etc/timezone
RUN dpkg-reconfigure --frontend noninteractive tzdata
RUN apt install -y apache2
ADD index.html /var/www/html/index.html
ENTRYPOINT ["/usr/sbin/apachectl"]
CMD ["-D", "FOREGROUND"]
EXPOSE 80
VOLUME /var/www/html
docker build --no-cache -t ubuntu-apache:v1.3 .
#include <stdio.h>
int main() {
printf("Hello C World!\n");
return 0;
}
sudo apt install gcc
gcc hello.c -o hello
./hello
Dockerfile
FROM ubuntu:focal
ADD hello /hello
CMD ["/hello"]
docker build -t chello .
docker run chello
실행 안됨
ldd hello
mkdir -p lib/x86_64-linux-gnu
mkdir lib64
cp /lib/x86_64-linux-gnu/libc.so.6 lib/x86_64-linux-gnu/
cp /lib64/ld-linux-x86-64.so.2 lib64/
Dockerfile
FROM scratch
ADD hello /hello
ADD lib /lib
ADD lib64 /lib64
CMD ["/hello"]
docker build -t chello .
이미지 내부 파일 경로
/hello
/lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
스태틱 바이너리
gcc hello.c --static -o hello-static
ldd hello-static
Dockerfile
FROM scratch
ADD hello-static /hello-static
CMD ["/hello-static"]
docker build -t cstatichello .
docker run cstatichello