Best Practices for Debugging Vagrants + Docker + Flask
My goal is to start a flask web server from a Docker container. Working with a Windows machine requires Vagrant to create a virtual machine. Running tramp up --provider = docker results in the following complaint:
INFO interface: error: The container started either never left the "stopped" state or
very quickly reverted to the "stopped" state. This is usually
because the container didn't execute a command that kept it running,
and usually indicates a misconfiguration.
If you meant for this container to not remain running, please
set the Docker provider configuration "remains_running" to "false":
config.vm.provider "docker" do |d|
d.remains_running = false
end
This is my Dockerfile
FROM mrmrcoleman/python_webapp
EXPOSE 5000
# Install Python
RUN apt-get install -y python python-dev python-distribute python-pip
# Add and install Python modules
RUN pip install Flask
#copy the working directory to the container
ADD . /
CMD python run.py
And this is Vagrantfile
Vagrant.configure("2") do |config|
config.vm.provider "docker" do |d|
d.build_dir = "." #searches for a local dockerfile
end
config.vm.synced_folder ".", "/vagrant", type: "rsync"
rsync__chown = false
end
Since Vagrantfile and run.py work without issue independently, I suspect I have made a mistake in the Dockerfile. My question is twofold:
- Is there something clearly wrong with the Dockerfile or Vagrantfile?
- Is there a way to get the vagrant / docker more specific error messages?
source to share
I think the answer I was looking for is using the roaming docker-log command. I broke the Dockerfile because I didn't recognize the good behavior as such, because nothing really happens if the application is working as it should. docker-logs confirms that the flask app is listening for requests.
source to share
Is there something clearly wrong with the Dockerfile or Vagrantfile?
Your Dockerfile and Vagrantfiles look good, but I think you need to change the run.py permissions to execute:
...
#copy the working directory to the container
ADD . /
RUN chmod +x run.py
CMD python run.py
It works?
Is there a way for vagrant / docker to produce more specific error messages?
Try taking a look at the vagrant debug page . Another approach I am using is to enter the container and try to run the script manually.
# log onto the vm running docker
vagrant ssh
# start your container in bash, assuming its already built.
docker run -it my/container /bin/bash
# now from inside your container try to start your app
python run.py
Also, if you want to view your application locally, you want to add port forwarding to your Vagrantfile.
source to share