Docker Compose Getting Started guide

2019-07-25 01:05发布

问题:

I'm following the Docker Compose getting started guide (https://docs.docker.com/compose/gettingstarted/) and I've followed the guide exactly. My Dockerfile, docker-compose.yml, and all other files in the directory are exactly as they appear in the guide.

However, when I attempt to run docker-compose up, the web service exits immediately with an exit code of 2, and an error message:

web_1    | python: can't open file 'app.py': [Errno 2] No such file or directory

Building and running an image works fine if the run by itself, i.e.

docker build -t composetestweb .
docker run -d -p 5000:5000 composetestweb

The website spits out an error, but it does respond.

Inspecting the composed container appears to present the correct information: the command, mounted folders, and working directory are all correct.

I'm using Docker Machine on Windows 7 with VirtualBox 4.3.38. For the record, I haven't had any problems with any other Docker guides up to this point.

回答1:

The most common cause of this error is using docker-machine and a project output of your $HOME directory. docker-machine will only create a Virtualbox shared folder for the home directory, so if your project is outside of that directory the volumes: used in the docker-compose will not work.

You have the following options:

  • move the project to a directory under your home directory
  • add another shared folder to virtualbox for the folder where you store your projects
  • don't use volumes:, removing it from the docker-compose