Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Docker on Mac, build works, run errors: : /bin/sh: 1: [: missing ]

Tags:

bash

docker

macos

Running Docker on Mac, I can build my image, but on running, I get the following error:

/bin/sh: 1: [: missing ]

I create the image in a local directory with a dockerfile, requirements.txt and a python script file. - 3 files- using docker build

Dockerfile:

FROM python
COPY "requirements.txt"
RUN pip install -r requirements.txt
COPY "quandlData.py"
CMD [ "python", "./quandlData.py" 

-simple script that gets some data from quandl API and writes-gets from a redis server- which is running. To run, I just use docker run image_name

like image 476
Dumbo Avatar asked Feb 07 '17 22:02

Dumbo


People also ask

Does Docker work on M1 Mac?

You can even now run ARM or Intel Docker containers on the Apple M1 Mac with Docker Desktop for Mac M1. The default, of course, is to run the ARM version but if you use the –platform linux/amd64 parameter Docker will run the Intel version for you.

Where are Dockerfiles stored Mac?

On a Mac, the default location for Docker images is ~/Library/Containers/com. docker.


1 Answers

CMD [ "python", "./quandlData.py"

is being parsed as a shell command, not an array -- and the [ command (when invoked that way, rather than by its alternate name test) requires its last argument to be ].

In this case, however, adding a trailing ] will cause your CMD to parse as an array describing arguments to pass to python, not a [ command at all -- which it should be.


Thus, you can do either of these two things:

# BETTER: Fix your JSON array
CMD [ "python", "./quandlData.py" ]

...or...

# WORSE: Pass a valid shell command
CMD python ./quandlData.py
like image 156
Charles Duffy Avatar answered Nov 15 '22 16:11

Charles Duffy