当前位置:K88软件开发文章中心编程语言GoGo01 → 文章内容

Docker 安装 Tomcat

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-11 12:56:14

OMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz \    https:





//www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz \    https:





//archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gzENV TOMCAT_ASC_URLS \    https:





//www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz.asc \





# not all the mirrors actually carry the .asc files :





'(    https:





//www-us.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz.asc \    https:





//www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz.asc \    https:





//archive.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz.ascRUN set -eux; \    \    savedAptMark="$(apt-mark showmanual)"; \    apt-get update; \    \    apt-get install -y --no-install-recommends gnupg dirmngr; \    \    export GNUPGHOME="$(mktemp -d)"; \    for key in $GPG_KEYS; do \        gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \    done; \    \    apt-get install -y --no-install-recommends wget ca-certificates; \    \    success=; \    for url in $TOMCAT_TGZ_URLS; do \        if wget -O tomcat.tar.gz "$url"; then \            success=1; \            break; \        fi; \    done; \    [ -n "$success" ]; \    \    echo "$TOMCAT_SHA512 *tomcat.tar.gz" | sha512sum -c -; \    \    success=; \    for url in $TOMCAT_ASC_URLS; do \        if wget -O tomcat.tar.gz.asc "$url"; then \            success=1; \            break; \        fi; \    done; \    [ -n "$success" ]; \    \    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*; \    rm -rf "$GNUPGHOME"; \    \    nativeBuildDir="$(mktemp -d)"; \    tar -xvf bin/tomcat-native.tar.gz -C "$nativeBuildDir" --strip-components=1; \    apt-get install -y --no-install-recommends \        dpkg-dev \        gcc \        libapr1-dev \        libssl-dev \        make \        "openjdk-${JAVA_VERSION%%[.~bu-]*}-jdk=$JAVA_DEBIAN_VERSION" \    ; \    ( \        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 "$(nproc)"; \        make install; \    ); \    rm -rf "$nativeBuildDir"; \    rm bin/tomcat-native.tar.gz; \    \





# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies    apt-mark auto '.*' > /dev/null; \    [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \    apt-get purge -y --auto-remove -o APT:





:





AutoRemove:





:





RecommendsImportant=false; \    rm -rf /var/lib/apt/lists/*; \    \





# sh removes env vars it doesn't support (ones with periods)





# https:





//github.com/docker-library/tomcat/issues/77    find ./bin/ -name '*.sh' -exec sed -ri 's|^





#!/bin/sh$|





#!/usr/bin/env bash|' '{}' +





# verify Tomcat Native is working properlyRUN 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; \    fiEXPOSE 8080CMD ["catalina.sh", "run"]通过Dockerfile创建一个镜像,替换成你自己的名字k88@k88:





~/tomcat$ docker build -t tomcat .创建完成后,我们可以在本地的镜像列表里查找到刚刚创建的镜像k88@k88:





~/tomcat$ docker images|grep tomcattomcat latest 70f819d3d2d9 7 days ago 335.8 MB使用tomcat镜像运行容器k88@k88:





~/tomcat$ docker run --name tomcat -p 8080:





8080 -v $PWD/test:





/usr/local/tomcat/webapps/test -d tomcat acb33fcb4beb8d7f1ebace6f50f5fc204b1dbe9d524881267aa715c61cf75320k88@k88:





~/tomcat$命令说明:-p 8080:





8080:将容器的8080端口映射到主机的8080端口-v $PWD/test:





/usr/local/tomcat/webapps/test:将主机中当前目录下的test挂载到容器的/test查看容器启动情况k88@k88:





~/tomcat$ docker ps CONTAINER ID IMAGE COMMAND ... PORTS NAMESacb33fcb4beb tomcat "catalina.sh run" ... 0.0.0.0:





8080->8080/tcp tomcat通过浏览器访问

上一页  [1] [2] 


Docker 安装 Tomcat