I have a docker-compose.yml file, and part of it sets up a MySQL docker container.
Below is the part of the file:
version: "2.2"
services:
mysql:
image: mysql:5.7
hostname: mysql
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: slurm_acct_db
MYSQL_USER: slurm
MYSQL_PASSWORD: password
MYSQL_ROOT_HOST: "%"
MYSQL_HOST: "%"
ports:
- '3306:3306'
volumes:
- var_lib_mysql:/var/lib/mysql
I can log into the MySQL server from the container with:
mysql -u slurm -ppassword
But if I remove the volumes and make changes to the docker-compose.yml
e.g. change MYSQL_PASSWORD
in the docker-compose.yml
file it doesn’t seem to have an effect and the old password is still used.
It is probably very obvious, but I can’t seem to find a way for the changes to take effect. Can someone point me in the right direction?
2
Answers
So I found the issue.
I had started this app using docker-compose in one directory, whilst playing around. I then started the project in a different directory, and docker-compose continued to read the
.yml
file from the first directory, not the current directory I was working in.Deleted the old directory, and started with
docker-compose up -d
from the second directory I was currently working in, and now the changes have been read.look to make your compose file appears immediately then you have to run the command:
docker-compose up -d
this will have the update done for you.
or you have another solution that you create another environment variable outside the compose file and then you will need to update the run again to have an effect as it reads the variables immediately from the current file and any effects have to be applied first.