- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章基于alpine用dockerfile创建的tomcat镜像的实现由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
1、下载alpine镜像 。
1
2
3
4
5
6
7
8
9
10
|
[root@docker43 ~]
# docker pull alpine
Using default tag: latest
Trying to pull repository docker.io
/library/alpine
...
latest: Pulling from docker.io
/library/alpine
4fe2ade4980c: Pull complete
Digest: sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Status: Downloaded newer image
for
docker.io
/alpine
:latest
[root@docker43 ~]
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io
/alpine
latest 196d12cf6ab1 3 weeks ago 4.41 MB
|
2、通过dockerfile构建镜像 。
在其他的资料中很多都是下载包然后在dockerfile 使用COPY进行拷贝,这里我就不这样做了,我们分开写(都是通过dockerfile进行构建镜像) 。
2.1.构建jdk镜像 。
创建jdk目录 。
1
2
3
4
5
|
[root@docker43 ~]
# cd /opt/
[root@docker43 opt]
# mkdir -p alpine_jre && cd alpine_jre && touch Dockerfile
[root@docker43 alpine_jre]
# ll
总用量 0
-rw-r--r-- 1 root root 0 10月 6 17:39 Dockerfile
|
编写dockerfile文件 。
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
|
# 基础镜像
FROM alpine
# 作者信息
MAINTAINER JRE Docker Maintainers
"1024331014@qq.com"
# 修改源
RUN
echo
"http://mirrors.aliyun.com/alpine/latest-stable/main/"
>
/etc/apk/repositories
&& \
echo
"http://mirrors.aliyun.com/alpine/latest-stable/community/"
>>
/etc/apk/repositories
# 安装需要的软件
RUN apk update && \
apk add --no-cache ca-certificates && \
apk add --no-cache curl
bash
tree tzdata && \
cp
-rf
/usr/share/zoneinfo/Asia/Shanghai
/etc/localtime
# 定义环境变量
ENV PATH
/usr/local/bin
:${PATH}
# 安装JRE
RUN apk add --nocache openjdk8-jre-base && \
rm
-rf
/var/cache/apk/
*
RUN { \
echo
'#!/bin/sh'
; \
echo
'set -e'
; \
echo
; \
echo
'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'
; \
} >
/usr/local/bin/docker-java-home
\
&&
chmod
+x
/usr/local/bin/docker-java-home
ENV JAVA_HOME
/usr/lib/jvm/default-jvm
ENV PATH ${PATH}:${JAVA_HOME}
/bin
:${JAVA_HOME}
/jre/bin
ENV JAVA_VERSION 8u71
ENV JAVA_ALPINE_VERSION 8.171.11-r0
RUN
set
-x \
\
&& apk add --no-cache \
\
openjdk8-jre=
"$JAVA_ALPINE_VERSION"
|
创建镜像 。
1
|
[root@docker43 alpine_jre]
# docker build -t alpine_jre .
|
查看镜像 。
1
2
3
4
|
[root@docker43 alpine_jre]
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine_jre latest 614bc57ab66e 33 seconds ago 91.1 MB
docker.io
/alpine
latest 196d12cf6ab1 3 weeks ago 4.41 MB
|
2.2.构建tomcat镜像 。
创建tomcat目录 。
1
2
3
4
5
|
[root@docker43 ~]
# cd /opt/
[root@docker43 opt]
# mkdir -p jre_tomcat && cd jre_tomcat && touch Dockerfile
[root@docker43 jre_tomcat]
# ll
总用量 0
-rw-r--r-- 1 root root 0 10月 6 17:46 Dockerfile
|
编写dockerfile(基于上面的alpine_jre镜像) 。
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
|
#基础镜像
FROM alpine_jre
# 作者信息
MAINTAINER tomcat Docker Maintainers
"1024331014@qq.com"
# 定义tomcat变量(如果有其他的可以在这里加)
ENV CATALINA_HOME
/usr/local/tomcat
ENV PATH $CATALINA_HOME
/bin
:$PATH
RUN
mkdir
-p
"$CATALINA_HOME"
WORKDIR $CATALINA_HOME
# let "Tomcat Native" live somewhere isolated
ENV TOMCAT_NATIVE_LIBDIR $CATALINA_HOME
/native-jni-lib
ENV LD_LIBRARY_PATH ${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$TOMCAT_NATIVE_LIBDIR
RUN apk add --no-cache gnupg
# see http://archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/KEYS
# see also "update.sh" (https://github.com/docker-library/tomcat/blob/master/update.sh)
ENV GPG_KEYS 05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23
RUN
set
-ex; \
for
key
in
$GPG_KEYS;
do
\
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys
"$key"
; \
done
# 定义tomcat版本
ENV TOMCAT_MAJOR 8
ENV TOMCAT_VERSION 8.0.53
# 下载
# https://issues.apache.org/jira/browse/INFRA-8753?focusedCommentId=14735394#comment-14735394
ENV TOMCAT_TGZ_URL https:
//www
.apache.org
/dyn/closer
.cgi?action=download&filename=tomcat
/tomcat-
$TOMCAT_MAJOR
/v
$TOMCAT_VERSION
/bin/apache-tomcat-
$TOMCAT_VERSION.
tar
.gz
# not all the mirrors actually carry the .asc files :'(
ENV TOMCAT_ASC_URL http:
//archive
.apache.org
/dist/tomcat/tomcat-
$TOMCAT_MAJOR
/v
$TOMCAT_VERSION
/bin/apache-tomcat-
$TOMCAT_VERSION.
tar
.gz.asc
# 安装
RUN
set
-x \
\
&& apk add --no-cache --virtual .fetch-deps \
ca-certificates \
tar
\
openssl \
&& wget -O tomcat.
tar
.gz
"$TOMCAT_TGZ_URL"
\
&& wget -O tomcat.
tar
.gz.asc
"$TOMCAT_ASC_URL"
\
&& gpg --batch --verify tomcat.
tar
.gz.asc tomcat.
tar
.gz \
&&
tar
-xvf tomcat.
tar
.gz --strip-components=1 \
&&
rm
bin/*.bat \
&&
rm
tomcat.
tar
.gz* \
\
&& nativeBuildDir=
"$(mktemp -d)"
\
&&
tar
-xvf bin
/tomcat-native
.
tar
.gz -C
"$nativeBuildDir"
--strip-components=1 \
&& apk add --no-cache --virtual .native-build-deps \
apr-dev \
dpkg-dev dpkg \
gcc \
libc-dev \
make
\
"openjdk${JAVA_VERSION%%[-~bu]*}"
=
"$JAVA_ALPINE_VERSION"
\
openssl-dev \
&& ( \
export
CATALINA_HOME=
"$PWD"
\
&&
cd
"$nativeBuildDir/native"
\
&& gnuArch=
"$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"
\
&& .
/configure
\
--build=
"$gnuArch"
\
--libdir=
"$TOMCAT_NATIVE_LIBDIR"
\
--prefix=
"$CATALINA_HOME"
\
--with-apr=
"$(which apr-1-config)"
\
--with-java-home=
"$(docker-java-home)"
\
--with-ssl=
yes
\
&&
make
-j$(getconf _NPROCESSORS_ONLN) \
&&
make
install
\
) \
&& runDeps="$( \
scanelf --needed --nobanner --recursive
"$TOMCAT_NATIVE_LIBDIR"
\
|
awk
'{ gsub(/,/, "\nso:", $2); print "so:" $2 }'
\
|
sort
-u \
|
xargs
-r apk info --installed \
|
sort
-u \
)" \
&& apk add --virtual .tomcat-native-rundeps $runDeps \
&& apk del .fetch-deps .native-build-deps \
&&
rm
-rf
"$nativeBuildDir"
\
&&
rm
bin
/tomcat-native
.
tar
.gz
# verify Tomcat Native is working properly
RUN
set
-e \
&& nativeLines=
"$(catalina.sh configtest 2>&1)"
\
&& nativeLines=
"$(echo "
$nativeLines
" | grep 'Apache Tomcat Native')"
\
&& nativeLines=
"$(echo "
$nativeLines
" | sort -u)"
\
&&
if
!
echo
"$nativeLines"
|
grep
'INFO: Loaded APR based Apache Tomcat Native library'
>&2;
then
\
echo
>&2
"$nativeLines"
; \
exit
1; \
fi
# 开发8080端口
EXPOSE 8080
# 执行命令
CMD [
"catalina.sh"
,
"run"
]
|
创建镜像 。
1
|
[root@docker43 jre_tomcat]
# docker build -t tomcat:1.0 .
|
查看镜像 。
1
2
3
4
5
|
[root@docker43 jre_tomcat]
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 1.0 64c9cec4375d 7 seconds ago 124 MB
alpine_jre latest 614bc57ab66e 8 minutes ago 91.1 MB
docker.io
/alpine
latest 196d12cf6ab1 3 weeks ago 4.41 MB
|
2.3.构建tomcat_web镜像 。
创建tomcat_web目录(包含Dockerfile和启动文件) 。
1
2
3
4
5
6
|
[root@docker43 ~]
# cd /opt/
[root@docker43 opt]
# mkdir tomcat_web && cd tomcat_web && touch Dockerfile && touch start.sh
[root@docker43 tomcat_web]
# ll
总用量 0
-rw-r--r-- 1 root root 0 10月 6 17:53 Dockerfile
-rw-r--r-- 1 root root 0 10月 6 17:53 start.sh
|
编写start.sh启动脚本 。
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
# Control Script for the CATALINA Server
#
# Environment Variable Prerequisites
#
# Do not set the variables in this script. Instead put them into a script
# setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
#
# CATALINA_HOME May point at your Catalina "build" directory.
#
# CATALINA_BASE (Optional) Base directory for resolving dynamic portions
# of a Catalina installation. If not present, resolves to
# the same directory that CATALINA_HOME points to.
#
# CATALINA_OUT (Optional) Full path to a file where stdout and stderr
# will be redirected.
# Default is $CATALINA_BASE/logs/catalina.out
#
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.
#
# CATALINA_TMPDIR (Optional) Directory path location of temporary directory
# the JVM should use (java.io.tmpdir). Defaults to
# $CATALINA_BASE/temp.
#
# JAVA_HOME Must point at your Java Development Kit installation.
# Required to run the with the "debug" argument.
#
# JRE_HOME Must point at your Java Runtime installation.
# Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
# are both set, JRE_HOME is used.
#
# JAVA_OPTS (Optional) Java runtime options used when any command
# is executed.
# Include here and not in CATALINA_OPTS all options, that
# should be used by Tomcat and also by the stop process,
# the version command etc.
# Most options should go into CATALINA_OPTS.
#
# JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories
# containing some jars in order to allow replacement of APIs
# created outside of the JCP (i.e. DOM and SAX from W3C).
# It can also be used to update the XML parser implementation.
# Defaults to $CATALINA_HOME/endorsed.
#
# JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
# command is executed. The default is "dt_socket".
#
# JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
# command is executed. The default is localhost:8000.
#
# JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
# command is executed. Specifies whether JVM should suspend
# execution immediately after startup. Default is "n".
#
# JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
# command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
# and JPDA_SUSPEND are ignored. Thus, all required jpda
# options MUST be specified. The default is:
#
# -agentlib:jdwp=transport=$JPDA_TRANSPORT,
# address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
#
# JSSE_OPTS (Optional) Java runtime options used to control the TLS
# implementation when JSSE is used. Default is:
# "-Djdk.tls.ephemeralDHKeySize=2048"
#
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of the catalina startup java process, when start (fork) is
# used
#
# LOGGING_CONFIG (Optional) Override Tomcat's logging config file
# Example (all one line)
# LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
#
# LOGGING_MANAGER (Optional) Override Tomcat's logging manager
# Example (all one line)
# LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
#
# USE_NOHUP (Optional) If set to the string true the start command will
# use nohup so that the Tomcat process will ignore any hangup
# signals. Default is "false" unless running on HP-UX in which
# case the default is "true"
# -----------------------------------------------------------------------------
# OS specific support. $var _must_ be set to either true or false.
cygwin=
false
darwin=
false
os400=
false
hpux=
false
case
"`uname`"
in
CYGWIN*) cygwin=
true
;;
Darwin*) darwin=
true
;;
OS400*) os400=
true
;;
HP-UX*) hpux=
true
;;
esac
# resolve links - $0 may be a softlink
PRG=
"$0"
while
[ -h
"$PRG"
];
do
ls
=`
ls
-ld
"$PRG"
`
link=`
expr
"$ls"
:
'.*-> \(.*\)$'
`
if
expr
"$link"
:
'/.*'
>
/dev/null
;
then
PRG=
"$link"
else
PRG=`
dirname
"$PRG"
`/
"$link"
fi
done
# Get standard environment variables
PRGDIR=`
dirname
"$PRG"
`
# Only set CATALINA_HOME if not already set
[ -z
"$CATALINA_HOME"
] && CATALINA_HOME=`
cd
"$PRGDIR/.."
>
/dev/null
;
pwd
`
# Copy CATALINA_BASE from CATALINA_HOME if not already set
[ -z
"$CATALINA_BASE"
] && CATALINA_BASE=
"$CATALINA_HOME"
# Ensure that any user defined CLASSPATH variables are not used on startup,
# but allow them to be specified in setenv.sh, in rare case when it is needed.
CLASSPATH=
if
[ -r
"$CATALINA_BASE/bin/setenv.sh"
];
then
.
"$CATALINA_BASE/bin/setenv.sh"
elif
[ -r
"$CATALINA_HOME/bin/setenv.sh"
];
then
.
"$CATALINA_HOME/bin/setenv.sh"
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if
$cygwin;
then
[ -n
"$JAVA_HOME"
] && JAVA_HOME=`cygpath --unix
"$JAVA_HOME"
`
[ -n
"$JRE_HOME"
] && JRE_HOME=`cygpath --unix
"$JRE_HOME"
`
[ -n
"$CATALINA_HOME"
] && CATALINA_HOME=`cygpath --unix
"$CATALINA_HOME"
`
[ -n
"$CATALINA_BASE"
] && CATALINA_BASE=`cygpath --unix
"$CATALINA_BASE"
`
[ -n
"$CLASSPATH"
] && CLASSPATH=`cygpath --path --unix
"$CLASSPATH"
`
fi
# Ensure that neither CATALINA_HOME nor CATALINA_BASE contains a colon
# as this is used as the separator in the classpath and Java provides no
# mechanism for escaping if the same character appears in the path.
case
$CATALINA_HOME
in
*:*)
echo
"Using CATALINA_HOME: $CATALINA_HOME"
;
echo
"Unable to start as CATALINA_HOME contains a colon (:) character"
;
exit
1;
esac
case
$CATALINA_BASE
in
*:*)
echo
"Using CATALINA_BASE: $CATALINA_BASE"
;
echo
"Unable to start as CATALINA_BASE contains a colon (:) character"
;
exit
1;
esac
# For OS400
if
$os400;
then
# Set job priority to standard for interactive (interactive - 6) by using
# the interactive priority - 6, the helper threads that respond to requests
# will be running at the same priority as interactive jobs.
COMMAND=
'chgjob job('
$JOBNAME
') runpty(6)'
system $COMMAND
# Enable multi threading
export
QIBM_MULTI_THREADED=Y
fi
# Get standard Java environment variables
if
$os400;
then
# -r will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
.
"$CATALINA_HOME"
/bin/setclasspath
.sh
else
if
[ -r
"$CATALINA_HOME"
/bin/setclasspath
.sh ];
then
.
"$CATALINA_HOME"
/bin/setclasspath
.sh
else
echo
"Cannot find $CATALINA_HOME/bin/setclasspath.sh"
echo
"This file is needed to run this program"
exit
1
fi
fi
# Add on extra jar files to CLASSPATH
if
[ ! -z
"$CLASSPATH"
] ;
then
CLASSPATH=
"$CLASSPATH"
:
fi
CLASSPATH=
"$CLASSPATH"
"$CATALINA_HOME"
/bin/bootstrap
.jar
if
[ -z
"$CATALINA_OUT"
] ;
then
CATALINA_OUT=
"$CATALINA_BASE"
/logs/catalina
.out
fi
if
[ -z
"$CATALINA_TMPDIR"
] ;
then
# Define the java.io.tmpdir to use for Catalina
CATALINA_TMPDIR=
"$CATALINA_BASE"
/temp
fi
# Add tomcat-juli.jar to classpath
# tomcat-juli.jar can be over-ridden per instance
if
[ -r
"$CATALINA_BASE/bin/tomcat-juli.jar"
] ;
then
CLASSPATH=$CLASSPATH:$CATALINA_BASE
/bin/tomcat-juli
.jar
else
CLASSPATH=$CLASSPATH:$CATALINA_HOME
/bin/tomcat-juli
.jar
fi
# Bugzilla 37848: When no TTY is available, don't output to console
have_tty=0
if
[
"`tty`"
!=
"not a tty"
];
then
have_tty=1
fi
# For Cygwin, switch paths to Windows format before running java
if
$cygwin;
then
JAVA_HOME=`cygpath --absolute --windows
"$JAVA_HOME"
`
JRE_HOME=`cygpath --absolute --windows
"$JRE_HOME"
`
CATALINA_HOME=`cygpath --absolute --windows
"$CATALINA_HOME"
`
CATALINA_BASE=`cygpath --absolute --windows
"$CATALINA_BASE"
`
CATALINA_TMPDIR=`cygpath --absolute --windows
"$CATALINA_TMPDIR"
`
CLASSPATH=`cygpath --path --windows
"$CLASSPATH"
`
JAVA_ENDORSED_DIRS=`cygpath --path --windows
"$JAVA_ENDORSED_DIRS"
`
fi
if
[ -z
"$JSSE_OPTS"
] ;
then
JSSE_OPTS=
"-Djdk.tls.ephemeralDHKeySize=2048"
fi
JAVA_OPTS=
"$JAVA_OPTS $JSSE_OPTS"
# Register custom URL handlers
# Do this here so custom URL handles (specifically 'war:...') can be used in the security policy
JAVA_OPTS=
"$JAVA_OPTS -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
# Set juli LogManager config file if it is present and an override has not been issued
if
[ -z
"$LOGGING_CONFIG"
];
then
if
[ -r
"$CATALINA_BASE"
/conf/logging
.properties ];
then
LOGGING_CONFIG=
"-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
else
# Bugzilla 45585
LOGGING_CONFIG=
"-Dnop"
fi
fi
if
[ -z
"$LOGGING_MANAGER"
];
then
LOGGING_MANAGER=
"-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
fi
# Uncomment the following line to make the umask available when using the
# org.apache.catalina.security.SecurityListener
#JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"
if
[ -z
"$USE_NOHUP"
];
then
if
$hpux;
then
USE_NOHUP=
"true"
else
USE_NOHUP=
"false"
fi
fi
unset
_NOHUP
if
[
"$USE_NOHUP"
=
"true"
];
then
_NOHUP=
nohup
fi
# ----- Execute The Requested Command -----------------------------------------
# Bugzilla 37848: only output this if we have a TTY
if
[ $have_tty -
eq
1 ];
then
echo
"Using CATALINA_BASE: $CATALINA_BASE"
echo
"Using CATALINA_HOME: $CATALINA_HOME"
echo
"Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
if
[
"$1"
=
"debug"
] ;
then
echo
"Using JAVA_HOME: $JAVA_HOME"
else
echo
"Using JRE_HOME: $JRE_HOME"
fi
echo
"Using CLASSPATH: $CLASSPATH"
if
[ ! -z
"$CATALINA_PID"
];
then
echo
"Using CATALINA_PID: $CATALINA_PID"
fi
fi
if
[
"$1"
=
"jpda"
] ;
then
if
[ -z
"$JPDA_TRANSPORT"
];
then
JPDA_TRANSPORT=
"dt_socket"
fi
if
[ -z
"$JPDA_ADDRESS"
];
then
JPDA_ADDRESS=
"localhost:8000"
fi
if
[ -z
"$JPDA_SUSPEND"
];
then
JPDA_SUSPEND=
"n"
fi
if
[ -z
"$JPDA_OPTS"
];
then
JPDA_OPTS=
"-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
fi
CATALINA_OPTS=
"$JPDA_OPTS $CATALINA_OPTS"
shift
fi
if
[
"$1"
=
"debug"
] ;
then
if
$os400;
then
echo
"Debug command not available on OS400"
exit
1
else
shift
if
[
"$1"
=
"-security"
] ;
then
if
[ $have_tty -
eq
1 ];
then
echo
"Using Security Manager"
fi
shift
exec
"$_RUNJDB"
"$LOGGING_CONFIG"
$LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.
dirs
=
"$JAVA_ENDORSED_DIRS"
-classpath
"$CLASSPATH"
\
-sourcepath
"$CATALINA_HOME"
/../..
/java
\
-Djava.security.manager \
-Djava.security.policy==
"$CATALINA_BASE"
/conf/catalina
.policy \
-Dcatalina.base=
"$CATALINA_BASE"
\
-Dcatalina.home=
"$CATALINA_HOME"
\
-Djava.io.tmpdir=
"$CATALINA_TMPDIR"
\
org.apache.catalina.startup.Bootstrap
"$@"
start
else
exec
"$_RUNJDB"
"$LOGGING_CONFIG"
$LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.
dirs
=
"$JAVA_ENDORSED_DIRS"
-classpath
"$CLASSPATH"
\
-sourcepath
"$CATALINA_HOME"
/../..
/java
\
-Dcatalina.base=
"$CATALINA_BASE"
\
-Dcatalina.home=
"$CATALINA_HOME"
\
-Djava.io.tmpdir=
"$CATALINA_TMPDIR"
\
org.apache.catalina.startup.Bootstrap
"$@"
start
fi
fi
elif
[
"$1"
=
"run"
];
then
shift
if
[
"$1"
=
"-security"
] ;
then
if
[ $have_tty -
eq
1 ];
then
echo
"Using Security Manager"
fi
shift
eval
exec
"\"$_RUNJAVA\""
"\"$LOGGING_CONFIG\""
$LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.
dirs
=
"\"$JAVA_ENDORSED_DIRS\""
-classpath
"\"$CLASSPATH\""
\
-Djava.security.manager \
-Djava.security.policy==
"\"$CATALINA_BASE/conf/catalina.policy\""
\
-Dcatalina.base=
"\"$CATALINA_BASE\""
\
-Dcatalina.home=
"\"$CATALINA_HOME\""
\
-Djava.io.tmpdir=
"\"$CATALINA_TMPDIR\""
\
org.apache.catalina.startup.Bootstrap
"$@"
start
else
eval
exec
"\"$_RUNJAVA\""
"\"$LOGGING_CONFIG\""
$LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.
dirs
=
"\"$JAVA_ENDORSED_DIRS\""
-classpath
"\"$CLASSPATH\""
\
-Dcatalina.base=
"\"$CATALINA_BASE\""
\
-Dcatalina.home=
"\"$CATALINA_HOME\""
\
-Djava.io.tmpdir=
"\"$CATALINA_TMPDIR\""
\
org.apache.catalina.startup.Bootstrap
"$@"
start \
>>
"$CATALINA_OUT"
2>&1
fi
fi
|
编写dockerfile(基于上面的tomcat镜像) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# 基础镜像
FROM tomcat:1.0
# 创建项目目录和日志目录,这个是要在宿主机-v挂载的
RUN
set
-x \
&&
mkdir
-p
/Webs/logs
\
\
&&
rm
-rf
/usr/local/tomcat/logs
\
\
&&
ln
-sf
/Webs/logs
/usr/local/tomcat/logs
# 将启动文件copy到容器
COPY start.sh
/usr/local/tomcat/bin/
# 给容器的启动脚本权限
RUN
chmod
+x
/usr/local/tomcat/bin/start
.sh
# 开放8080端口
EXPOSE 8080
# 运行tomcat
CMD [
"start.sh"
,
"run"
]
|
创建镜像 。
1
|
[root@docker43 tomcat_web]
# docker build -t tomcat_web:v1 .
|
查看镜像 。
1
2
3
4
5
6
|
[root@docker43 tomcat_web]
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat_web v1 b3651c50a7b5 26 seconds ago 124 MB
tomcat 1.0 64c9cec4375d 6 minutes ago 124 MB
alpine_jre latest 614bc57ab66e 14 minutes ago 91.1 MB
docker.io
/alpine
latest 196d12cf6ab1 3 weeks ago 4.41 MB
|
3、创建容器 。
创建项目目录 。
我们是基于tomcat_web镜像进行创建容器的 。
首先我先在宿主机上创建个项目的目录(server.xml的配置文件拷贝改路径就能用) 。
1
2
3
4
5
6
7
8
9
10
|
[root@docker43 ~]
# cd /home/
[root@docker43 home]
# mkdir test.tomcat.com && cd test.tomcat.com
[root@docker43
test
.tomcat.com]
# touch server.xml # 配置文件
[root@docker43
test
.tomcat.com]
# mkdir logs # 日志目录
[root@docker43
test
.tomcat.com]
# mkdir wwwroot # 项目主目录(要是修改了记得也在server.xml进行修改)
[root@docker43
test
.tomcat.com]
# ll
总用量 0
drwxr-xr-x 2 root root 6 10月 6 18:03 logs
-rw-r--r-- 1 root root 0 10月 6 18:02 server.xml
drwxr-xr-x 2 root root 6 10月 6 18:03 wwwroot
|
server.xml配置文件 。
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
|
<?
xml
version
=
'1.0'
encoding
=
'utf-8'
?>
<
Server
port
=
"8005"
shutdown
=
"SHUTDOWN"
>
<
Listener
className
=
"org.apache.catalina.startup.VersionLoggerListener"
/>
<
Listener
className
=
"org.apache.catalina.core.AprLifecycleListener"
SSLEngine
=
"on"
/>
<
Listener
className
=
"org.apache.catalina.core.JreMemoryLeakPreventionListener"
/>
<
Listener
className
=
"org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
/>
<
Listener
className
=
"org.apache.catalina.core.ThreadLocalLeakPreventionListener"
/>
<
GlobalNamingResources
>
<
Resource
name
=
"UserDatabase"
auth
=
"Container"
type
=
"org.apache.catalina.UserDatabase"
description
=
"User database that can be updated and saved"
factory
=
"org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname
=
"conf/tomcat-users.xml"
/>
</
GlobalNamingResources
>
<
Service
name
=
"Catalina"
>
<
Connector
port
=
"8080"
protocol
=
"org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout
=
"20000"
maxThreads
=
"1000"
minSpareThreads
=
"100"
redirectPort
=
"8443"
URIEncoding
=
"UTF-8"
/>
<
Connector
port
=
"8009"
maxThreads
=
"1000"
minSpareThreads
=
"100"
protocol
=
"AJP/1.3"
redirectPort
=
"8443"
/>
<
Engine
name
=
"Catalina"
defaultHost
=
"localhost"
>
<
Realm
className
=
"org.apache.catalina.realm.LockOutRealm"
>
<
Realm
className
=
"org.apache.catalina.realm.UserDatabaseRealm"
resourceName
=
"UserDatabase"
/>
</
Realm
>
<
Host
name
=
"localhost"
appBase
=
"/Webs/wwwroot"
unpackWARs
=
"true"
autoDeploy
=
"true"
>
<
Context
path
=
""
docBase
=
"/Webs/wwwroot"
reloadable
=
"true"
/>
<
Valve
className
=
"org.apache.catalina.valves.AccessLogValve"
directory
=
"logs"
prefix
=
"localhost__access_log"
suffix
=
".txt"
pattern
=
"%{X-Real-IP}i %l %u %t "%r" %s %b"
/>
</
Host
>
</
Engine
>
</
Service
>
</
Server
>
|
编写测试页面 。
在wwwroot中编写个测试页面 。
1
2
|
[root@docker43
test
.tomcat.com]
# cd wwwroot/
[root@docker43 wwwroot]
# cat index.html
|
成功了 。
创建并启动容器 。
。
查看容器 。
1
2
3
|
[root@docker43
test
.tomcat.com]
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab62045e0688 tomcat_web:v1
"start.sh run -con..."
2 seconds ago Up 1 second 0.0.0.0:5081->8080
/tcp
test
.tomcat.com
|
测试 。
1
2
3
|
[root@docker43
test
.tomcat.com]
# curl 127.0.0.1:5081
成功了
[root@docker43
test
.tomcat.com]
#
|
4、温馨提示 。
1、各位肯定会问我问什么要做这么多的镜像,我的回答是每个都独立出来 放在之后的私有仓库中,以后可以单独的使用 。
2、这篇文章的代码都完全的可以直接的复制粘贴使用,要注意的是根据自己的情况来修改Dockerfile的变量版本,还有就是项目的路径和创建容器的参数 。
3、我们在创建第二个项目的使用,完全可以重复的执行创建容器的步骤只是修改下项目目录的名字和容器的名字而已 。
4、也可以把上面的三个dockerfile文件合并创建镜像,但是不建议这样做 。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:http://www.cnblogs.com/zhujingzhi/p/9746760.html 。
最后此篇关于基于alpine用dockerfile创建的tomcat镜像的实现的文章就讲到这里了,如果你想了解更多关于基于alpine用dockerfile创建的tomcat镜像的实现的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我希望在某些环境中使用用户名和密码保护某个角色,但在其他环境中甚至不需要提示。如果我在 tomcat web.xml 中有一个 auth-constraint,我可以创建一个具有“匿名”访问权限的角色
我正在使用 Tomcat jmxproxy 和状态来监视 Web 应用程序,但是 jmxproxy 页面中有很多无用的信息,并且其中没有任何信息,例如事件连接数。有谁知道如何过滤 jmxproxy 页
是否可以通过执行 JSP 来重启 Tomcat6? 这是因为我想通过使用网络服务器远程部署应用程序的更改。 部署脚本是用 bash 编写的,它从 svn 中 check out 最新版本,然后将其打包
我有一个包含 2 个子项目(后端和 ui)的 gradle 项目。 Ui由gradle tomcatRunWar完美启动.后端有我们在生产地点的配置描述符/conf/Catalina/localhos
发现 XAMPP 控件认为 tomcat 正在运行但无法停止它的问题。 在catalina下的tomcat logs目录下可以找到如下错误 “严重:无法联系 localhost:8005。Tomcat
PuppetLabs 在 PuppetForge 上有一个模块,用于部署 Tomcat 及其配置。 https://forge.puppet.com/puppetlabs/tomcat Tomcat
我有一个部署到 Tomcat 实例中的 Web 应用程序。我希望能够将 tomcat 配置为在 Tomcat 本身启动时不自动启动该应用程序。但是,我确实希望启动 Tomcat 管理器,以便我可以根据
操作系统:windows XP。 我已经安装了 Tomcat 7.0.25,文件夹“manager”位于 webapps 文件夹中。 我已阅读此处的文档:http://tomcat.apache.or
我们在 server.xml 文件中启用了以下访问日志模式 pattern="%h %H %l %u %t "%r" %s %b location: %{location}o"。 有人可以帮助理解模式
我最近开始使用 tomcat,我有一个关于 Tomcat 请求路由/映射的查询。 假设我在 tomcat 服务器中部署了四个应用程序 A、B、C 和 D,当有请求到来时,tomcat 如何知道要调用哪
我在我的计算机上使用 Tomcat,它可以通过端口 8080 访问。我想要的是我应该能够使用我的计算机的 IP 地址访问我的 Tomcat 服务器页面。我以前读过很多主题,但找不到一个可以帮助我的主题
我有一个 tomcat 7 服务器和一个 postgreSQL 9.0 数据库。我用它来为地理网络元数据编辑器设置开发环境。一切都是根据 geonetwork 网站教程设置的。我在将服务器与数据库连接
我的服务器有 物理 ip 和 虚拟 ip 由网络管理员设置。在我安装的服务器内部 Apache tomcat 7.0.29并创建一个网络应用程序。当我运行 wget http://:8080/xxx或
我有多个应用程序在不同的端口上运行(tomcat 实例) 都有相同的CATALINA_HOME 目前我必须在所有实例中部署和安装psi 探针,并在不同的窗口中分别监控每个端口。 我如何在一个单一的探测
based on this question 我尝试将 Tomcat 控制台输出重定向到一个文本文件,它对我的 Web 应用程序工作正常,但问题是,每次 Tomcat 启动时它都会被覆盖。我需要创
我需要阐明我的问题。问题是:有什么方法可以影响 Tomcat 为特定部署的应用程序分配多少堆内存?更多详细信息 - 我如何为已部署的应用程序设置特定的 Java 选项(考虑我想为每个应用程序设置特殊的
应用服务器内部的类加载机制是开发人员常见的困惑来源;这就是为什么我想问一个关于 tomcat 7 服务器中这个机制的问题:我有一个网络应用程序 sample.war,它依赖于 jgroups 库, 放
尝试将嵌入式 Tomcat 5 迁移到嵌入式 Tomcat 7。在启动过程中获取 NPE。 我扩展了 Embedded 类并按照正确的顺序执行所有建议的初始化。 NPE 发生在这里: Caused b
我可以使用随附的 start.sh 文件启动 tomcat,但是是否有任何参数可以用来执行以下操作: 在指定的根目录启动 Tomcat 服务 强制 Tomcat 在浏览器中拉出指定的主页 谢谢 最佳答
我在两台 diff 机器 tomcat 服务器上做一个简单的集群配置。每次我启动 tomcat 时,我都会收到一个错误,就像集群组中没有事件成员一样。我正在附加集群配置
我是一名优秀的程序员,十分优秀!