How to run multiple commands in docker at once?

+1 vote

I'm trying to execute multiple commands like this.

docker run image cd /some/path && python a.py

But I get a "No such file or directory" error.

Jul 19, 2018 in Docker by Tyrion anex
• 8,270 points
20,086 views

11 answers to this question.

0 votes

In order to run multiple commands in docker, use /bin/bash -c with a semicolon ;

docker run image /bin/bash -c "cd /some/path; python a.py"

In this case the second command (python) will be executed only if the first command (cd) returns no error or an exit status. To avoid this use && instead of ; (semi-colon)

docker run image /bin/bash -c "cd /some/path && python a.py"
answered Jul 19, 2018 by Sophie may
• 9,850 points
0 votes

Pass the entire argument to /bin/bash:

docker run image /bin/bash -c "cd /path/to/somewhere; python a.py"
answered Nov 27, 2018 by krishti
0 votes

You can pipe commands inside Docker container

bash -c "<command_1> | <command_2>"

answered Nov 27, 2018 by akaash
0 votes

You can pipe commands inside Docker container, bash -c "<command1> | <command2>"for example:

docker run img /bin/bash -c "ls -1 | wc -l"
answered Dec 10, 2018 by Abhi
0 votes

Hey @Tyrion, Replace your entrypoint with sh /www/docker-start.sh. Hope it helps

answered Dec 10, 2018 by Zoo
0 votes

 The issue seems to be with the entrypoint script /docker-entrypoint.sh. The script needs to have executable permission (chmod +x).

answered Dec 10, 2018 by Shrishti
0 votes

Try running the following commad:

["bash", "/start_up.sh"]

answered Dec 10, 2018 by Vedant
0 votes

If non of these solutions work, try adding this in your start_up.sh file to get more details about the failure.

set -x

answered Dec 10, 2018 by Haider
0 votes

Change this in your dockerfile:

CMD ["/run.sh"]
to
ENTRYPOINT ["/bin/bash", "/run.sh"]
answered Dec 10, 2018 by Laksha
0 votes

Hey @Tyrion, Are you running on local machine or remote? If you mount any volume at your source directory (where script is located) it might override entire directory and thus unable to find your script.

answered Dec 10, 2018 by Akaash
0 votes

Try this:

docker run image bash -c "cd /some/path && python a.py"
or /bin/sh
answered Apr 17 by anonymous

edited Apr 17 by Kalgi
Thanks, it worked for me.

Related Questions In Docker

0 votes
1 answer
0 votes
1 answer

How to create a container and run images in docker?

Look for what all images you have ...READ MORE

answered Feb 22 in Docker by Kalgi
• 41,660 points
99 views
+1 vote
2 answers

How to run docker containers on different machines

You can use labels and selectors for ...READ MORE

answered Oct 23, 2018 in Docker by Laila
87 views
0 votes
1 answer

How to store data in external drive with Docker Postgres:9.3 image?

Apparently, the problem would be in your ...READ MORE

answered Jul 12, 2018 in Docker by Kalgi
• 2,620 points
140 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,900 points
189 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,850 points
365 views
0 votes
1 answer