根据https://github.com/apache/activemq-artemis/tree/main/artemis-docker文档可以进行安装
下载Docker对应配置文件
https://github.com/apache/activemq-artemis/tree/main/artemis-docker
将下面的文件下载到本地 (本次是基于jdk进行镜像的生成,因此只需要下载Dockerfile-adoptopenjdk-11即可)
* Dockerfile-adoptopenjdk-11
* docker-run.sh
* prepare-docker.sh
使用上面的脚本执行下面的命令
# 从服务器上拉取2.19.0版本artemis
sh prepare-docker.sh --from-release --artemis-version 2.19.0
构建镜像
# 进入下载的artemis目录
cd _TMP_/artemis/2.19.0
# 构建镜像
docker build -f ./docker/Dockerfile-adoptopenjdk-8 -t artemis-adoptopenjdk-8 .
启动容器
docker run --rm -it -p 61616:61616 -p 8161:8161 artemis-adoptopenjdk-8
下载文件中是以jdk11为原始镜像处理的,这里改成了jdk1.8
prepare-docker.sh
该文件无无需处理,如果提示tree命令找不到时,可以使用brew install tree
进行安装
#!/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.
# Setting the script to fail if anything goes wrong
set -e
#This is a script to Prepare an artemis folder to generate the Release.
usage () {
cat <<HERE
$@
Usage:
# Prepare for build the Docker Image from the local distribution
./prepare-docker.sh --from-local-dist --local-dist-path {local-distribution-directory}
# Prepare for build the Docker Image from the release version
./prepare-docker.sh --from-release --artemis-version {release-version}
# Show the usage command
./prepare-docker.sh --help
Example:
./prepare-docker.sh --from-local-dist --local-dist-path ../artemis-distribution/target/apache-artemis-2.17.0-SNAPSHOT-bin/apache-artemis-2.17.0-SNAPSHOT
./prepare-docker.sh --from-release --artemis-version 2.16.0
HERE
exit 1
}
next_step () {
cat <<HERE
Well done! Now you can continue with the Docker image build.
Building the Docker Image:
Go to $ARTEMIS_DIST where you prepared the binary with Docker files.
# Go to $ARTEMIS_DIST
$ cd $ARTEMIS_DIST
# For Debian
$ docker build -f ./docker/Dockerfile-debian -t artemis-debian .
# For CentOS
$ docker build -f ./docker/Dockerfile-centos -t artemis-centos .
# For AdoptOpen JDK 11
$ docker build -f ./docker/Dockerfile-adoptopenjdk-11 -t artemis-adoptopenjdk-11 .
# For AdoptOpen JDK 11 (Build for linux ARMv7/ARM64)
$ docker buildx build --platform linux/arm64,linux/arm/v7 --push -t {your-repository}/apache-artemis:2.17.0-SNAPSHOT -f ./docker/Dockerfile-adoptopenjdk-11 .
Note: -t artemis-debian, -t artemis-centos and artemis-adoptopenjdk-11 are just
tag names for the purpose of this guide
For more info read the readme.md
HERE
exit 1
}
while [ "$#" -ge 1 ]
do
key="$1"
case $key in
--help)
usage
;;
--from-local-dist)
FROM_LOCAL="true"
;;
--from-release)
FROM_RELEASE="true"
;;
--local-dist-path)
LOCAL_DIST_PATH="$2"
shift
;;
--artemis-version)
ARTEMIS_VERSION="$2"
shift
;;
*)
# unknown option
usage "Unknown option"
;;
esac
shift
done
# TMPDIR must be contained within the working directory so it is part of the
# Docker context. (i.e. it can't be mktemp'd in /tmp)
BASE_TMPDIR="_TMP_/artemis"
echo $BASE_TMPDIR
echo ${BASE_TMPDIR}/${ARTEMIS_VERSION}
cleanup() {
if [ -d "${BASE_TMPDIR}/${ARTEMIS_VERSION}" ]
then
echo "Clean up the ${BASE_TMPDIR}/${ARTEMIS_VERSION} directory"
find "${BASE_TMPDIR}" -name "${ARTEMIS_VERSION}" -type d -mmin +60 -exec rm -rf "{}" \;
else
mkdir -p "${BASE_TMPDIR}/${ARTEMIS_VERSION}"
fi
}
if [ -n "${FROM_RELEASE}" ]; then
[ -n "${ARTEMIS_VERSION}" ] || usage "You must specify the release version (es.: --artemis-version 2.16.0)"
cleanup
ARTEMIS_BASE_URL="$(curl -s https://www.apache.org/dyn/closer.cgi\?preferred=true)activemq/activemq-artemis/${ARTEMIS_VERSION}/"
ARTEMIS_DIST_FILE_NAME="apache-artemis-${ARTEMIS_VERSION}-bin.tar.gz"
CURL_OUTPUT="${BASE_TMPDIR}/${ARTEMIS_VERSION}/${ARTEMIS_DIST_FILE_NAME}"
if [ -z "$(ls -A ${BASE_TMPDIR}/${ARTEMIS_VERSION})" ]
then
echo "Downloading ${ARTEMIS_DIST_FILE_NAME} from ${ARTEMIS_BASE_URL}..."
curl --progress-bar "${ARTEMIS_BASE_URL}${ARTEMIS_DIST_FILE_NAME}" --output "${CURL_OUTPUT}"
echo "Expanding ${BASE_TMPDIR}/${ARTEMIS_VERSION}/${ARTEMIS_DIST_FILE_NAME}..."
tar xzf "$CURL_OUTPUT" --directory "${BASE_TMPDIR}/${ARTEMIS_VERSION}" --strip 1
echo "Removing ${BASE_TMPDIR}/${ARTEMIS_VERSION}/${ARTEMIS_DIST_FILE_NAME}..."
rm -rf "${BASE_TMPDIR}/${ARTEMIS_VERSION}"/"${ARTEMIS_DIST_FILE_NAME}"
fi
ARTEMIS_DIST="${BASE_TMPDIR}/${ARTEMIS_VERSION}"
echo "Using Artemis dist: ${ARTEMIS_DIST}"
elif [ -n "${FROM_LOCAL}" ]; then
if [ -n "${LOCAL_DIST_PATH}" ]; then
ARTEMIS_DIST=${LOCAL_DIST_PATH}
echo "Using Artemis dist: ${ARTEMIS_DIST}"
else
usage "You must specify the local distribution directory"
fi
echo "-----------------------------"
if [ ! -d "${ARTEMIS_DIST}" ]
then
usage "Directory ${ARTEMIS_DIST} does not exist"
fi
if [ -d "${ARTEMIS_DIST}/docker" ]
then
echo "Clean up the ${ARTEMIS_DIST}/docker directory"
rm -rf "${ARTEMIS_DIST}/docker"
fi
else
usage
fi
if [ ! -d "${ARTEMIS_DIST}/docker" ]
then
mkdir "${ARTEMIS_DIST}/docker"
fi
cp ./Dockerfile-* "$ARTEMIS_DIST/docker"
cp ./docker-run.sh "$ARTEMIS_DIST/docker"
echo "Docker file support files at : $ARTEMIS_DIST/docker"
tree "$ARTEMIS_DIST/docker"
next_step
docker-run.sh
#!/bin/bash
# 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.
# This is the entry point for the docker images.
# This file is executed when docker run is called.
set -e
BROKER_HOME=/var/lib/
CONFIG_PATH=$BROKER_HOME/etc
export BROKER_HOME OVERRIDE_PATH CONFIG_PATH
if [[ ${ANONYMOUS_LOGIN,,} == "true" ]]; then
LOGIN_OPTION="--allow-anonymous"
else
LOGIN_OPTION="--require-login"
fi
CREATE_ARGUMENTS="--user ${ARTEMIS_USER} --password ${ARTEMIS_PASSWORD} --silent ${LOGIN_OPTION} ${EXTRA_ARGS}"
echo CREATE_ARGUMENTS=${CREATE_ARGUMENTS}
if ! [ -f ./etc/broker.xml ]; then
/opt/activemq-artemis/bin/artemis create ${CREATE_ARGUMENTS} .
else
echo "broker already created, ignoring creation"
fi
exec ./bin/artemis "$@"
Dockerfile-adoptopenjdk-8
# 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.
# ActiveMQ Artemis
FROM openjdk:8u312
LABEL maintainer="Apache ActiveMQ Team"
# Make sure pipes are considered to determine success, see: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /opt
# 账号
ENV ARTEMIS_USER admin
# 密码
ENV ARTEMIS_PASSWORD 123456
# 是否允许匿名登录
ENV ANONYMOUS_LOGIN true
ENV EXTRA_ARGS --http-host 0.0.0.0 --relax-jolokia
# add user and group for artemis
RUN groupadd -g 1000 -r admin && useradd -r -u 1000 -g admin admin \
&& apt-get -qq -o=Dpkg::Use-Pty=0 update && \
apt-get -qq -o=Dpkg::Use-Pty=0 install -y libaio1 && \
rm -rf /var/lib/apt/lists/*
USER admin
ADD . /opt/activemq-artemis
# Web Server
EXPOSE 8161 \
# JMX Exporter
9404 \
# Port for CORE,MQTT,AMQP,HORNETQ,STOMP,OPENWIRE
61616 \
# Port for HORNETQ,STOMP
5445 \
# Port for AMQP
5672 \
# Port for MQTT
1883 \
#Port for STOMP
61613
USER root
RUN mkdir /var/lib/artemis-instance && chown -R admin.admin /var/lib/artemis-instance
COPY ./docker/docker-run.sh /
USER admin
# Expose some outstanding folders
VOLUME ["/var/lib/artemis-instance"]
WORKDIR /var/lib/artemis-instance
ENTRYPOINT ["/docker-run.sh"]
CMD ["run"]