Development workflow for docker compose: run the dev-version container
I have a pretty typical docker-compose setup: a custom web container and a database container directly from the docker hub. For development, my host directory is mounted in web docker, so I don't have to rebuild the container every time I make small changes. The web server is a Passenger (standalone) serving a ruby ​​application.
When I run it, I have my database running, my webservice running (on port 3000), all is well. However, if I make the changes, nothing changes as the web server (passenger) has to be restarted. I would like to be able to start a simple lightweight development server, for example thin
, which I would manually restart when I make a change.
What I have tried:
- Starting a new web container (
docker-compose run web ...
) does not provide any port for the new container. Thus, I cannot connect to the webserver. - Starting a new web container with Docker directly (
docker run web -p 5000:5000 image_name ...
). We are losing docker compose functionality, the container is not database bound without manual bindings. - Re-doing the docker compose every time (as it starts quickly). Every time my database is reloaded so empty I need to keep working.
- Use Argument
--service-ports
: Don't work as port 3000 is already in use -
docker exec
my dev server is in a web container: should be running on a different port, so won't show up. -
docker exec
kill
my webserver: it actually works (restarts) but I don't really like this solution. First, since the server is still a Passenger, where would I prefer a lightweight web server (likethin
). Secondly, it is not very convenient for me to connect to the server usingdocker exec ...
. - Modifying mine
Dockerfile
to replace Passenger by automatically restarting the dev webserver: I like it toDockerfile
be the same as prod, tests and dev.
Do you have a simple and easy way to start my web container with open port 5000 on which I would enable starting / restarting the dev webserver?
source to share
I am using two files for docker compose, one for development and one for build.
In developing a docker compose file, you can override CMD
from your Dockerfile with command
so that you can easily use bash
to create a shell or use an automatic server restart.
To use a custom docker-compose file, follow these steps: docker-compose -f dev.yml ...
And for this:
Re-executing the docker compose every time (as it starts up). Every time my database is reloaded so empty I need to keep working.
If you do docker-compose up --no-deps web
it won't restart your db
source to share