Docker Community Forums

Share and learn in the Docker community.

Exited with code 1 Help


#1

exited with code 1

i have this error when

command: bash -c "mkdir 4433"

version: '3.2'

services:
  web:
    image: php:7-apache
    depends_on:
      - db
    restart: always
    ports:
      - 80:80
    command: bash -c "mkdir 4433"
  db:
    image: mysql:5.7.24
    restart: always
    ports:
      - 3306:3306

when this

version: '3.2'

services:
  web:
    image: php:7-apache
    depends_on:
      - db
    restart: always
    ports:
      - 80:80
  db:
    image: mysql:5.7.24
    restart: always
    ports:
      - 3306:3306

Its work fine…

this is error

mysql_web_1 exited with code 1
mysql_web_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/dbfcd0b6373406a45324bf0bead231cfe1564720d88ebf8147ba1103c967df25/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 dbfcd0b6373406a45324bf0bead231cfe1564720d88ebf8147ba1103c967df25 is restarting, wait until the container is running'")

(Martin Terp) #2

Hi

its because you override the default command, that the container wants to run at startup.
And because of the way docker works, the container will stop after its command is run.

So, when you override the command with “mkdir”, it will run the command and stop the container.
And since you have defined that it needs to “restart always” it will just run in a loop where it starts up, mkdir, dies.
Normally it would have started the apache deamon.


#3

so, how can i run .sh file in container? can you give little example ???


(Martin Terp) #4

So you want to run some commands before the apache deamon starts?


#5

i want run come command before the MySQL deamon starts. Can you help me, give me example???