how to automate docker development environment startup for a multi-service web app (on Linux)
I currently have to do the following 9+ steps just to launch my dev stack using Docker on Ubuntu 16.04 before I can start writing code:
- open a terminal and cd into service #1’s source code directory
- docker-compose up service #1 (Python/Django, Redis, and Postgres containers)
- docker exec service1 bash; start Django dev server for debugging
- repeat for service #2, using terminal tabs to keep things organized
- open a terminal and cd into the front-end Angular app source directory
- run a webpack dev server with npm
- open one or more terminals and cd into the appropriate source code directories to edit
I tried writing a shell script to launch everything with
gnome-terminal --tab -e "bash -c docker-compose up", etc, but this gets awkward and will fail when trying to then shell into containers and run things, e.g.
gnome-terminal --tab -e "bash -c \"docker-compose exec service1 bash -c rundev.sh \"". I also tried using
xdotool, but it can’t identify the docker shell terminal tabs for some reason.
Running a SPA with two back-end services and doing local development on each of the three code-bases doesn’t seem like a bizarre use-case for Docker app development to me.
Does anyone have any suggestions of tools or an alternative dev environment setup for simplifying things?
One Solution collect form web for “how to automate docker development environment startup for a multi-service web app (on Linux)”
You can do it with a bash script, but the proper way would be docker-compose. You need to create 2x services with their respective commands to run. Here is an example for rails app. Your docker-compose.yml should be something similar to this.
version: '2' services: db: image: postgres web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000" depends_on: - db