Open parc02 opened 9 months ago
$ vi pull.sh
<<파일 내부>>
#!/bin/bash
echo "start pull-->" date "+%Y-%m-%d %H:%M:%S"
cd /home/parc02/code/parc02.github.io git pull
echo "<--end pull"
$ vi blog-pull-cronjob
<<파일 내부>>
으로 변경
$ cp blog-pull-cronjob /etc/cron.d
$ crontab /etc/cron.d/blog-pull-cronjob
$ crontab -l
[FYI]
cp blog-pull-cronjob /etc/cron.d
: 이 명령은 blog-pull-cronjob
파일을 /etc/cron.d
디렉토리로 복사합니다.
crontab /etc/cron.d/blog-pull-cronjob
: 이 명령은 /etc/cron.d
디렉토리에 있는 blog-pull-cronjob
설정 파일을 사용하여 cron 작업을 설정합니다.
crontab -l
: 이 명령은 현재 사용자에 대한 cron 작업을 나열합니다. 이 명령을 실행하여 blog-pull-cronjob
가 성공적으로 설치되었는지 확인할 수 있습니다.
-CHAT GPT
$ sh pull.sh
start pull-->
2024-02-15 21:28:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:29:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:30:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:31:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:32:01
Already up to date.
<--end pull
$vi Dockerfile
FROM ubuntu:22.04
RUN apt update
RUN apt install -y nginx
RUN apt install -y git
RUN apt install cron
RUN rm -rf /var/www/html
RUN git clone https://github.com/parc02/parc02.github.io.git /var/www/html
COPY pull.sh /var/www/html/
COPY blog-pull-cronjob /etc/cron.d
RUN crontab /etc/cron.d/blog-pull-cronjob
RUN crontab -l
CMD service cron start; nginx -g 'daemon off;'
* * * * * sh /var/www/html//pull.sh >> /var/log/pull.log 2>&1
# new crontab file is missing newline before EOF, can't install.
#!/bin/bash
echo "start pull-->"
date "+%Y-%m-%d %H:%M:%S"
cd /var/www/html
git pull
echo "<--end pull"
$sudo docker build -t cron-1 .
[+] Building 24.8s (15/15) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 342B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:22.04 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 1.33kB 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 51.36kB 0.1s
=> [ 1/10] FROM docker.io/library/ubuntu:22.04 0.0s
=> CACHED [ 2/10] RUN apt update 0.0s
=> CACHED [ 3/10] RUN apt install -y nginx 0.0s
=> [ 4/10] RUN apt install -y git 15.9s
=> [ 5/10] RUN apt install cron 3.7s
=> [ 6/10] COPY . /var/www/html/ 2.3s
=> [ 7/10] COPY pull.sh /var/www/html/ 0.2s
=> [ 8/10] COPY blog-pull-cronjob /etc/cron.d 0.1s
=> [ 9/10] RUN crontab /etc/cron.d/blog-pull-cronjob 0.7s
=> [10/10] RUN crontab -l 0.6s
=> exporting to image 0.9s
=> => exporting layers 0.8s
=> => writing image sha256:0bac0db7f7f3a74060465012ba390e50f1e8df96018198d74355a803d81b918b 0.0s
=> => naming to docker.io/library/cron-1 0.0s
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cron-1 latest 0bac0db7f7f3 About a minute ago 393MB
$ sudo docker run -it -p 8111:80 --name cron-1 73b3c17ccf88 bash
$ sh pull.sh
start pull-->
2024-02-15 14:12:18
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? ^C
=>풀 땡길때 인증이 안된거 같다
$service cron start
명령어를 작성하면 1분후에 pull.log가 생성된다 도커파일 CMD는 하나만 작성 가능하고 두개이상 작성되었을시 가장 마지막 명령만 수행한다.
(There can only be one CMD instruction in a Dockerfile. If you list more than one CMD, only the last one takes effect.)[DOCKER_DOCS](https://docs.docker.com/engine/reference/builder/#dockerfile-reference)
이 문제였다.
bash
명령어를 치면 DOCKERFILE의 CMD와 중복 사용되게 돼서, 가장 마지막 명령어인 bash만 수행하게 된다.
$ sudo docker run -it -p 8111:80 --name cron-1 73b3c17ccf88 bash
https://github.com/beyond-sw-camp/be01-101/issues/39#issue-2135881343