Mahadevan G
Mahadevan G

Reputation: 35

Docker Compose - MySQL - MYSQL_ROOT_PASSWORD

Not able to start mysql container using docker-compose.yaml file, when I use '$' sign for the MYSQL_ROOT_PASSWORD.

I tried with the other special character '@' and it is starting up.

my docker-compose.yml file

version: '3.3'
services:
  database:
    container_name: mysql-dev2
    image: mysql:8.0
    volumes:
      - "./data/mysql-dev2:/var/lib/mysql-dev2-docker"
    # restart: always
    environment:
      MYSQL_DATABASE: mysqldb2
      MYSQL_ROOT_PASSWORD: Welcome123$
    ports:
      # <Port exposed> : < MySQL Port running inside container>
      - '3307:3306'
    expose:
      # Opens port 3307 on the container
      - '3307'
# Names our volume
volumes:
  mysql-dev2:
The error which I am getting
    F:\docker\mysql-dev2>docker-compose up
    ERROR: Invalid interpolation format for "environment" option in service "database": "Welcome123$"

If I change the MYSQL_ROOT_PASSWORD to 'Welcome123@', the mysql instance is started running.

help me on this.

regards, Mahadevan.G

Upvotes: 2

Views: 4487

Answers (1)

Neo Anderson
Neo Anderson

Reputation: 6360

You can escape the $ if with a double $$:

...
environment:
      MYSQL_DATABASE: mysqldb2
      MYSQL_ROOT_PASSWORD: Welcome123$$
...

Upvotes: 5

Related Questions