0%

参考链接 : https://medium.com/@hariomvashisth/cors-on-nginx-be38dd0e19df

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
server {
listen 80;
server_name api.test.com;


location / {

# Simple requests
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}

# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}

....
# Handle request
....
}
}

方法: 使用 docker [container] exec,container 可以省略,可以直接使用 docker exec

在使用 docker 容器的时候,我们总会想看看容器内部长什么样子: 我们可以使用 docker exec 命令。

现在,我们想通过 nginx -s reload 来重启 nginx 容器,可以使用下面的命令:

script
1
docker exec nginx nginx -s reload

上面第一个 nginx 是容器名称,nginx -s reload 是进入到容器后运行的命令。

如果我们想以交互的方式进入容器(类似 docker run):

script
1
docker exec -it centos bash

执行命令的目录: /Volumes/data/jenkins/workspace/qa3

报错

1
2
3
Cloning into '/home/web/deployer/Foundation/qa3/default/releases/20191022203935'...
fatal: Unable to read current working directory: Permission denied
fatal: index-pack failed

解决方法: 进入到对应目录执行 clone

cd /home/web/deployer/Foundation/qa3/default/releases && git clone xxx 20191022203935

cron 文件

hello-cron

1
2
* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
FROM ubuntu:latest
MAINTAINER docker@ekito.fr

RUN apt-get update && apt-get -y install cron

# Copy hello-cron file to the cron.d directory
COPY hello-cron /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron

# Apply cron job
RUN crontab /etc/cron.d/hello-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD cron && tail -f /var/log/cron.log

测试

script
1
2
docker build --rm -t ekito/cron-example .
docker run -it ekito/cron-example

说明

可以使用 cron -f 作为 dockerfile 的 CMD,这样会强制 crontab 前台运行

原文地址:

how-to-run-a-cron-job-inside-a-docker-container