For the same image, the docker command can start mysql, but the corresponding docker compose YML can't??

Alibaba cloud Q & A 2022-02-13 06:32:40 阅读数:289

image docker command start mysql

The mirror is docker hub A mirror image on , I start the corresponding container in the following two ways

docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-56-centos7

The startup container succeeded

docker-compose.yml

version: '2'services: mysql: image: centos/mysql-56-centos7:latest restart: always container_name: mysql

Environment profile .env It has the following contents

MYSQL_ROOT_PASSWORD=123456




Take the answer 1:

Hello! ,docker-compose It should be written in it environment To configure , otherwise .env Invalid , Don't read . Here's an example :

version: '2'services: env_file: # here - .env mysql: image: centos/mysql-56-centos7:latest restart: always container_name: mysql

perhaps

version: '2'services: environment: MYSQL_ROOT_PASSWORD: mysql: image: centos/mysql-56-centos7:latest restart: always container_name: mysql

copyright:author[Alibaba cloud Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130632389833.html