Run bash command after start service

So, i try to make this

FROM mysql:5.7.24

EXPOSE 8484

ENTRYPOINT mysql -u test -ptest test_db < sql/USERS.sql && /bin/bash

yml

version: '3.2'

services:
  db:
    build: ./db
    restart: always
    ports:
      - 3306:3306
    volumes:
      - ./sql:/sql

make
docker-compose build
docker-compose up

And have this

db_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1   | ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
web_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
web_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
web_1  | [Sun Jan 13 19:57:59.182024 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/5.6.39 configured -- resuming normal operations
web_1  | [Sun Jan 13 19:57:59.182208 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
mysql_db_1 exited with code 1
mysql_db_1 exited with code 1
Exception in thread Thread-7:
Traceback (most recent call last):
  File "site-packages/docker/api/client.py", line 246, in _raise_for_status
  File "site-packages/requests/models.py", line 940, in raise_for_status
requests.exceptions.HTTPError: 409 Client Error: Conflict for url: http+docker://localhost/v1.25/containers/0b7dd0ddf6d07bbb343f347be1743ab3d11b77f872f106d74e2e3873653b0b94/attach?logs=0&stdout=1&stderr=1&stream=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "threading.py", line 916, in _bootstrap_inner
  File "threading.py", line 864, in run
  File "compose/cli/log_printer.py", line 233, in watch_events
  File "compose/container.py", line 215, in attach_log_stream
  File "compose/container.py", line 307, in attach
  File "site-packages/docker/utils/decorators.py", line 19, in wrapped
  File "site-packages/docker/api/container.py", line 57, in attach
  File "site-packages/docker/api/client.py", line 385, in _read_from_socket
  File "site-packages/docker/api/client.py", line 296, in _get_raw_response_socket
  File "site-packages/docker/api/client.py", line 248, in _raise_for_status
  File "site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
docker.errors.APIError: 409 Client Error: Conflict ("b'container 0b7dd0ddf6d07bbb343f347be1743ab3d11b77f872f106d74e2e3873653b0b94 is restarting, wait until the container is running'")

Can any help me? why this crashing ???

Your Dockerfile is about mysql. You error log about an Apache webserver.You either pasted a wrong Dockerfile or log file.

You are aware the mysql Image has plenty of enviorenment variables dedicated for setting up the database? There is no reason to ā€œbrute forceā€ the behavior using an entrypoint scipt.

See section initializing-a-fresh-instance on https://hub.docker.com/_/mysql .

can you give me exampe how to import sql by enviorenment? i can`t find it

Did you even read the section initializing-a-fresh-instance on https://hub.docker.com/_/mysql?

So you want me to read the DockerHub page for your and summarize what you need?
The documentation is pretty straight forward.

1 Like