13

I want to run mysql on windows using docker container when i try use docker-compose up command on docker-compose file this the result.

> D:\dockerfiles>docker-compose up db_1 | Initializing database db_1 | 2018-10-08T09:00:29.024081Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) db_1 | 2018-10-08T09:00:29.024224Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) db_1 | 2018-10-08T09:00:29.024512Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). db_1 | 2018-10-08T09:00:29.028590Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. db_1 | 2018-10-08T09:00:29.028673Z 0 [ERROR] Aborting db_1 | dockerfiles_db_1 exited with code 1 

and this my docker-compose.yml

version: '3.7' services: db: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: pass MYSQL_DATABASE: star MYSQL_USER: user MYSQL_PASSWORD: pass 

update of docker compose file

version: '3.7' services: mysqldb: image: mysql:5.7 container_name: mysql_con1 command: --default-authentication-plugin=mysql_native_password command: --disable-partition-engine-check restart: always environment: MYSQL_ROOT_PASSWORD: pass MYSQL_DATABASE: star MYSQL_USER: user MYSQL_PASSWORD: pass volumes: - "./:/var/lib/mysql" networks: - samplenet networks: samplenet: driver: nat 
5
  • Welcome to SO. Please make sure that code blocks are surrounded by { and } for readability. Commented Oct 8, 2018 at 9:14
  • See github.com/docker-library/mysql/issues/290. Commented Oct 8, 2018 at 9:16
  • GitHub solution dose not work Commented Oct 8, 2018 at 9:25
  • Problem with - "./:/var/lib/mysql" is, current directory (./) is not empty. It contains docker-compose file. Commented Oct 8, 2018 at 17:04
  • i change '"./:/var/lib/mysql "' to " ./data" and the same error Commented Oct 8, 2018 at 17:40

4 Answers 4

14

There are some files in /var/lib/mysql directory. Remove everything from this directory. Or highly recommended, use volumes in docker-compose.yml.

volumes: - /my/own/datadir:/var/lib/mysql 

Update: I tested with the following compose file, it worked fine without any errors.

version: '3.7' services: db: image: mysql:5.7 restart: always volumes: - ./data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: pass MYSQL_DATABASE: star MYSQL_USER: user MYSQL_PASSWORD: pass 
Sign up to request clarification or add additional context in comments.

8 Comments

sorry for my little information but what is /my/own/datadir and /var/lib/mysql
/my/own/datadir is path where you want to store database files on your host machine & /var/lib/mysql is the path where mysql stores them in container.
But mysql Dockerfile adds default mount point VOLUME /var/lib/mysql, which instructs mysql container to store database files in /var/lib/mysql directory on host machine.
be sure to remove existing failed containers. you can use docker-compose down.
I do that and also delete old volumes
|
3

For those who ran the container using the docker run command and added the --detach|-d flag; Remove and rerun the container without the -d flag.

This should provide the error message to why it fails.

Comments

1

I got the same behaviour defining restaart=always, If I remove it everything went fine, and later I run command

docker update --restart=always {{ID OF CONTAINER}} 

Which makes it restart always. Hope this helps you.

Comments

0

Update Volume in docker-compose.yml

volumes: - /my/own/datadir:/var/lib/mysql 

Update: this compose file, it worked fine .

mysql: image: mysql:5.7.22 container_name: mysql restart: unless-stopped tty: true ports: - "3307:3306" volumes: - /my/own/datadir:/var/lib/mysql environment: MYSQL_USERNAME: "root" MYSQL_PASSWORD: "root" MYSQL_ROOT_PASSWORD: "root" MYSQL_DATABASE: test 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.