Vagrant Machine with Ubuntu 20.04 provisioned with both Docker Compose V1 and Compose V2 highlighting the problem of using / not using single-quotes for passwords with $
OS: Windows 10 with Windows Subsystem for Linux 2 (Ubuntu 20.04 LTS)
Tool | Version |
---|---|
vagrant (on WSL2 + Windows 10) |
2.2.19 |
Hyper-V |
10.0.19041.1 |
ansible (on WSL2) |
2.12.5 |
within the provisioned Vagrant Machine
Tool | Version |
---|---|
docker-compose |
v1.29.2 build 5b3cea4c , v1.25.4 build 8d51620a |
docker compose |
2.6.0 |
docker |
20.10.17 |
-
Bring the Vagrant machine up using:
vagrant up
-
Within the vagrant machine change to the sync folder
cd /vagrant/
For the following encrypted password via bcrypt
(plain-text value password
)
cat .env.node-red
NODERED_ADMIN_PASSWORD=$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.
Let Compose generate the configuration on STDOUT for you:
docker-compose-125 config
This will result in:
services:
node-red:
container_name: test-nodered
environment:
NODERED_ADMIN_PASSWORD: $$2a$$08$$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.
image: nodered/node-red:2.2.2
version: '3.9'
Compose V1 will escape the $
characters in the resolved password.
THIS WILL WORK
Let Compose generate the configuration on STDOUT for you:
docker-compose-129 config
This will result in:
services:
node-red:
container_name: test-nodered
environment:
NODERED_ADMIN_PASSWORD: $$2a$$08$$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.
image: nodered/node-red:2.2.2
version: '3.9'
Compose V1 will escape the $
characters in the resolved password.
THIS WILL WORK
Let Compose v2 generate the configuration STDOUT for you:
docker compose config
This will result in:
name: node-red-app
services:
node-red:
container_name: test-nodered
environment:
NODERED_ADMIN_PASSWORD: a$$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.
image: nodered/node-red:2.2.2
networks:
default: null
networks:
default:
name: node-red-app_default
Observe: the resolved password is broken. Compose V2 understands that the initial $
character is to be somehow
resolved hence when the container is up and running the password hashes won't match and you won't be able to
login to your system (here node-red Editor)
THIS WILL NOT WORK!
assuming the same password in the .env.node-red
file is enclosed in single quotes ''
cat conf/.env.node-red
NODERED_ADMIN_PASSWORD='$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.'
docker-compose-125 config
will result in:
services:
node-red:
container_name: test-nodered
environment:
NODERED_ADMIN_PASSWORD: '''$$2a$$08$$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.'''
image: nodered/node-red:2.2.2
version: '3.7'
Observe that the resolved password has more single quotes which will be part of the container's environment and hence the password hashes won't match and you won't be able to login to your system (here node-red Editor)
THIS WILL NOT WORK!
docker-compose-129 config
will result in:
services:
node-red:
container_name: test-nodered
environment:
NODERED_ADMIN_PASSWORD: $$2a$$08$$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.
image: nodered/node-red:2.2.2
version: '3.7'
This will work because the password is preserved
THIS WILL WORK
docker compose config
will result in:
name: node-red-app
services:
node-red:
container_name: test-nodered
environment:
NODERED_ADMIN_PASSWORD: $$2a$$08$$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.
image: nodered/node-red:2.2.2
networks:
default: null
networks:
default:
name: node-red-app_default
THIS WILL WORK
Compose Version / Values | 1.25.4 |
1.29.2 |
2.6.0 |
---|---|---|---|
with Single Quotes | ❌ | ✔️ | ✔️ |
without Single Quotes | ✔️ | ✔️ | ❌ |