DerPauli
DerPauli

Reputation: 63

docker-compose: MySQL service not running

I want to create a docker-compose file combining a custom maven environment, a specific runtime environment and a mysql server runtime. Compose file looks like this:

version: '3.7'
services:
  mysql:
    image: mysql:5.7.25
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_DATABASE: dbname
      MYSQL_USER: dbuser
      MYSQL_ROOT_PASSWORD: dbpass
    volumes:
      - ./mysql:/tmp

  maven:
    build: 
      context: ./maven
      args:
        git_user: gituser
        git_pw: gitpw
    command: tail -F anything

  runtime:
    image: custom_dockerhub_image
    links:
      - "mysql:db"
      - "maven:mav"
    volumes:
      - ./:/tmp
    command: tail -F anything

Services are all up and running and every volume gets bound in. I want to run a specific mysql script in my mysql container to setup my database. My first manual attempt was to just use

docker-compose run mysql mysql --user="dbuser" --password="dbpass" < "mysql/01_schema.sql"

The only response I get is

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Furthermore I tried to use

docker-compose run mysql service mysql start && mysql --user="dbuser" --password="dbpass" < "mysql/01_schema.sql"

The result was

..
[info] MySQL Community Server 5.7.25 is started.
zsh: command not found: mysql

I cant get the mysql server to stay.

Upvotes: 2

Views: 2249

Answers (1)

Esteban Garcia
Esteban Garcia

Reputation: 2283

You should use docker-compose exec instead, docker-compose run runs the command in a new container.

Upvotes: 3

Related Questions