【Docker实战之入门】init.sh脚本分析

前端之家收集整理的这篇文章主要介绍了【Docker实战之入门】init.sh脚本分析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<table class="text"><tr class="li1">
<td class="ln"><pre class="de1">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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

&2 'warning: both wordpress_DB_HOST and MysqL_PORT_3306_TCP found'                 echo >&2 "  Connecting to wordpress_DB_HOST ($wordpress_DB_HOST)"                 echo >&2 '  instead of the linked MysqL container'         fi fi   if [ -z "$wordpress_DB_HOST" ]; then         echo >&2 'error: missing wordpress_DB_HOST and MysqL_PORT_3306_TCP environment variables'         echo >&2 '  Did you forget to --link some_MysqL_container:MysqL or set an external db'         echo >&2 '  with -e wordpress_DB_HOST=hostname:port?'         exit 1 fi   # if we're linked to MysqL,and we're using the root user,and our linked # container has a default "root" password set up and passed through... :) : ${wordpress_DB_USER:=root} if [ "$wordpress_DB_USER" = 'root' ]; then         : ${wordpress_DB_PASSWORD:=$MysqL_ENV_MysqL_ROOT_PASSWORD} fi : ${wordpress_DB_NAME:=wordpress}   if [ -z "$wordpress_DB_PASSWORD" ]; then         echo >&2 'error: missing required wordpress_DB_PASSWORD environment variable'         echo >&2 '  Did you forget to -e wordpress_DB_PASSWORD=... ?'         echo >&2         echo >&2 '  (Also of interest might be wordpress_DB_USER and wordpress_DB_NAME.)'         exit 1 fi   if ! [ -e index.PHP -a -e wp-includes/version.PHP ]; then         echo >&2 "wordpress not found in $(pwd) - copying now..."         if [ "$(ls -A)" ]; then                 echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!"                 ( set -x; ls -A; sleep 10 )         fi         tar cf - --one-file-system -C /usr/src/wordpress . | tar xf -         echo >&2 "Complete! wordpress has been successfully copied to $(pwd)"         if [ ! -e .htaccess ]; then                 # NOTE: The "Indexes" option is disabled in the PHP:apache base image                 cat > .htaccess <<-'EOF'                         # BEGIN wordpress                                                 RewriteEngine On                         RewriteBase /                         RewriteRule ^index\.PHP$ - [L]                         RewriteCond %{REQUEST_FILENAME} !-f                         RewriteCond %{REQUEST_FILENAME} !-d                         RewriteRule . /index.PHP [L]                                                 # END wordpress                 EOF                 chown Nginx:Nginx .htaccess         fi fi   # TODO handle wordpress upgrades magically in the same way,but only if wp-includes/version.PHP's $wp_version is less than /usr/src/wordpress/wp-includes/version.PHP's $wp_version   if [ ! -e wp-config.php ]; then         awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.PHP > wp-config.php <<'EOPHP' // If we're behind a proxy server and using HTTPS,we need to alert wordpress of that fact // see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {         $_SERVER['HTTPS'] = 'on'; } EOPHP         chown Nginx:Nginx wp-config.php fi   set_config() {         key="$1"         value="$2"         PHP_escaped_value="$(PHP -r 'var_export($argv[1]);' "$value")"         sed_escaped_value="$(echo "$PHP_escaped_value" | sed 's/[\/&]/\\&/g')"         sed -ri "s/((['\"])$key\2\s*,\s*)(['\"]).*\3/\1$sed_escaped_value/" wp-config.php }   set_config 'DB_HOST' "$wordpress_DB_HOST" set_config 'DB_USER' "$wordpress_DB_USER" set_config 'DB_PASSWORD' "$wordpress_DB_PASSWORD" set_config 'DB_NAME' "$wordpress_DB_NAME"   # allow any of these "Authentication Unique Keys and Salts." to be specified via # environment variables with a "wordpress_" prefix (ie,"wordpress_AUTH_KEY") UNIQUES=(         AUTH_KEY         SECURE_AUTH_KEY         LOGGED_IN_KEY         NONCE_KEY         AUTH_SALT         SECURE_AUTH_SALT         LOGGED_IN_SALT         NONCE_SALT ) for unique in "${UNIQUES[@]}"; do         eval unique_value=\$wordpress_$unique         if [ "$unique_value" ]; then                 set_config "$unique" "$unique_value"         else                 # if not specified,let's generate a random value                 current_set="$(sed -rn "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"                 if [ "$current_set" = 'put your unique phrase here' ]; then                         set_config "$unique" "$(head -c1M /dev/urandom | sha1sum | cut -d' ' -f1)"                 fi         fi done   TERM=dumb PHP -- "$wordpress_DB_HOST" "$wordpress_DB_USER" "$wordpress_DB_PASSWORD" "$wordpress_DB_NAME" <<'EOPHP' connect_error) {                 # if not specified,(int)$port);         if ($MysqL->connect_error) {                 fwrite($stderr,"\n" . 'MysqL Connection Error: (' . $MysqL->connect_errno . ') ' . $MysqL->connect_error . "\n");                 --$maxTries;                 if ($maxTries <= 0) {                         exit(1);                 }                 sleep(3);         } } while ($mysql->connect_error); if (!$MysqL->query('CREATE DATABASE IF NOT EXISTS `' . $MysqL->real_escape_string($argv[4]) . '`')) {         fwrite($stderr,"\n" . 'MysqL "CREATE DATABASE" Error: ' . $MysqL->error . "\n");         $MysqL->close();         exit(1); } $MysqL->close(); EOPHP   //执行完了本脚本以后,@符号表示会执行dockerfile中entrypoint后面的指令 entrypoint ["/init.sh","/usr/bin/supervisord","-n","-c","/etc/supervisord.conf"] exec "$@"   //把PHPPHP-fpm启动起来。

猜你在找的Docker相关文章