1

Here's the chunk of code calling the ARG:

RUN \
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - && \
echo "deb http://www.rabbitmq.com/debian/ testing main" > /etc/apt/sources.list.d/rabbitmq.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y rabbitmq-server && \
rm -rf /var/lib/apt/lists/* && \
rabbitmq-plugins enable rabbitmq_management && \
echo '[{rabbit, [{loopback_users, []}, {default_user,<<"${RABBITMQ_USER}">>}, {default_pass,<<"${RABBITMQ_PASSWD}">>}]}].' > /etc/rabbitmq/rabbitmq.config

Note the RABBITMQ_PASSWD and RABBITMMQ_USER args

Before this chunk of code, I declared this at the start of the Dockerfile:

FROM ubuntu:14.04
ARG RABBITMQ_USER=123
ARG RABBITMQ_PASSWD=123

And it still isn't working. In the Docker image, cat rabbitmq.config returns ${RABBITMQ_USER} verbatim.

nubela
  • 1
  • 24
  • 75
  • 123

1 Answers1

2

Nothing wrong with ARG command. You are trying to expand variable inside a single quote in a bash command which is not possible.

Expansion of variable inside single quotes in a command in bash shell script

All you need to do is use double quotes and escape inner double quotes as follows.

echo "[{rabbit, [{loopback_users, []}, {default_user,<<\"${RABBITMQ_USER}\">>}, {default_pass,<<\"${RABBITMQ_PASSWD}\">>}]}]." > /etc/rabbitmq/rabbitmq.config
Community
  • 1
  • 1
atv
  • 1,950
  • 4
  • 21
  • 26