Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql docker container exited with code 1

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
like image 237
Mohamed Ahmed Sayed Avatar asked Oct 08 '18 09:10

Mohamed Ahmed Sayed


People also ask

Why does my docker container exit?

This happens if you run a foreground container (using docker run ), and then press Ctrl+C when the program is running. When this happens, the program will stop, and the container will exit. The container has been stopped using docker stop : You can manually stop a container using the docker stop command.

Is the docker CLI working exit status 1?

Common exit codes associated with docker containers are: Exit Code 0: Absence of an attached foreground process. Exit Code 1: Indicates failure due to application error.


2 Answers

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
like image 183
Dhirendra Avatar answered Oct 17 '22 19:10

Dhirendra


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.

like image 24
Osoro Avatar answered Oct 17 '22 17:10

Osoro