Skip to content

Docker: useful tips and commands

David Cook edited this page Jan 25, 2023 · 9 revisions

After setting up your docker environment you need to know how to go about doing things, here's some help.

Tips

If you dont want to run docker as root: https://docs.docker.com/engine/install/linux-postinstall/

EXEC vs RUN Note that there is a difference between exec/run. Run boots any required containers while exec expects a docker-compose run to happen beforehand. If you execute commands using run you'll end up with trillions of running containers 💥

Previewing emails

We use letter_opener to automatically opens up emails in your browser, but that doesn’t work in a virtual environment, so you may see these errors in your console:


openfoodnetwork-worker-1   | /usr/bin/xdg-open: 869: Couldn't find a suitable web browser!
openfoodnetwork-worker-1   | Set the BROWSER environment variable to your desired browser.

There are a few options you can try, see https://github.com/ryanb/letter_opener#remote-alternatives or https://www.youtube.com/watch?v=Ubrr9mqE94o. Feel free to submit a PR if you have a solution!

FAQs

To run any of these commands, you need a container running first, so you should do this first: sudo docker-compose up --build

  • How to have a bash interface inside the container? sudo docker-compose exec web bash

  • How to run a command inside the container? sudo docker-compose exec web bash -c 'bundle install'

  • How to run karma tests inside the container: sudo docker-compose exec web bash -c 'bundle exec rake karma:start'

  • How to access the database that the web container is using? docker-compose exec db psql -U ofn -d open_food_network_dev

Clone this wiki locally