-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple bash commands #2033
Comments
Running this via cmd line works, so perhaps the command needs prefixed with something? |
Found it! finally. http://stackoverflow.com/a/30064175/2363935
|
If you're running that many commands, wouldn't it be better to use a Dockerfile? |
@thaJeztah what makes the Dockerfile a better choice? I plan to use the same Dockerfile, but run some slightly different commands and configurations per environment i.e. |
I'm sorry, but I found a way for the multiline :) https://github.com/indiehosters/piwik/blob/master/docker-compose.yml#L29-L36 Feedback is welcomed :) |
Dockerfile just is not suitable for some commands. Let's say we want to run database migrations before app is started. It can't be done from Dockerfile because database server is not launched at the moment and event it's hostname (from Using |
Correct; the Dockerfile is meant to build the image (e.g. install the software that needs to be in the image); doing so allows you to test the actual image you're going to run before deploying it. Installing the software at runtime could make it a hit and miss; for example, packages you're installing may have been updated since you last tried, and there's no way to verify what went into the image you are running. For actions that are needed at runtime , consider using an entrypoint script (see here for an example) that checks if migration is needed, performs the migration, and after migration has completed, switches to the container's main process, using |
@thaJeztah Thank you for useful hints. I'm actually not an expert in Docker and I like that most things works as expected. But this particular case seems very confusing to me. It would be good to have an option to specify list for Special script for entry point can solve problems, but it also can be the source of problems by itself :) More code = more chances for errors. And with command: >
bash -c "./manage.py migrate &&
./manage.py collectstatic --noinput &&
./manage.py runserver 0.0.0.0:8000" Yes we could add an extra script which chains these commands but its already a bunch of devops scripts in modern projects :) I think that explicit call of standard script. i.e. And we don't always want to call all commands, for example there could be: command: ./manage.py runworkers |
Putting the code in the Having said that, I fully understand that sometimes a longer "command" may be needed; docker-compose is a bit tied to what the yaml format supports here.
This may not be easy; we need to take into account that command:
- "bash -c"
- "./manage.py migrate &&"
- "./manage.py collectstatic --noinput &&"
- "./manage.py runserver 0.0.0.0:8000" Which would result in; bash -c ./manage.py migrate && ./manage.py collectstatic --noinput && ./manage.py runserver 0.0.0.0:8000 Notice the missing quotes in that case; working around that would quickly lead to command:
- "bash -c \""
- "./manage.py migrate &&"
- "./manage.py collectstatic --noinput &&"
- "./manage.py runserver 0.0.0.0:8000\"" Not sure if that would be more readable than the current situation 😞 |
@thaJeztah I would expect commands to run separately one after another: command:
- ./manage.py migrate
- ./manage.py collectstatic --noinput
- ./manage.py runserver 0.0.0.0:8000 Just like if I'd run:
but with all extra options provided by Actually I think current approach is fine and disadvantages are minor. Just probably it could be better, I don't know about possible pitfalls. |
That won't be possible; a container runs as long as it's primary process is running; the container will stop the moment the first command completes. It's a bit different when running interactively; in that case |
@thaJeztah I see, sounds like a major change. Just an idea, to keep prepare:
- ./manage.py migrate
- ./manage.py collectstatic --noinput
command: manage.py runserver 0.0.0.0:8000 |
Any progress on this? |
@rudyryk |
you can do it like this
|
@rosskevin in my case I didn't have bash, so I used |
What about having another
|
within a command command is it possible to use variables? Something like : |
Unsupported config option for services.python: 'prepare' |
This is quite lame that I haven't understood the design reason for this, nor the technical restriction if any. But at least, shouldn't there be a warning somewhere? I lost much time on this and I guess I'm not the only one! |
Have you tried; command: "sh -c 'first_command && second_command'" |
Thanks @thaJeztah for getting back.
Just a workaround then. |
I have tried all approaches mentioned above, but nothing works as of now. Any ideas? What else I could try? |
I'm having problems issuing multiple commands:
Unknown switches '--all'
I'm sure it's simple but I'm pulling my hair out. What's the best way to do this (I don't want it in an external script).
If I remove the second statement, I get
ERROR: "bundle install" was called with arguments ["&&", "bin/rake", "log:clear", "&&", "bundle", "exec", "docker-rails-db-check", "&&", "bin/rake", "db:rebuild_test"]
, so this seems to be a simple bash usage failure on my part.The text was updated successfully, but these errors were encountered: