I enjoy a lot using docker-compose.
Eg. on my server, when I want to update my app with minor changes, I only need to git pull origin master && docker-compose restart
, works perfectly.
But sometimes, I need to rebuild (eg. I added an npm dependency, need to run npm install
again).
In this case, I do docker-compose build --no-cache && docker-compose restart
.
I would expect this to :
But in practice it seems to restart the former one again.
Is it the expected behavior?
How can I handle a rebuild and start the new one after it is built?
Maybe I missed a specific command? Or would it make sense to have it?
you should use docker-compose up first of all if its your first time your deploy code. and then run the update_server script to update your changes without any downtime.
The easy solution to keeping your Docker containers updated is simply to add another container, Watchtower. This simple image will watch your existing containers and upgrade them as newer builds are released, no questions asked.
from the manual docker-compose restart
If you make changes to your docker-compose.yml configuration these changes will not be reflected after running this command.
you should be able to do
$docker-compose up -d --no-deps --build <service_name>
The --no-deps
will not start linked services.
The problem is that restart
will restart your current containers, which is not what you want.
As an example, I just did this
docker-compose build
to build the imagesdocker-compose down
1 and docker-compose up
docker-compose restart
will NOT work heredocker-compose start
instead also does not workTo be honest, i'm not completly sure you need to do a down
first, but that should be easy to check.1 The bottomline is that you need to call up
. You will see the containers of unchanged images restarting, but for the changed image you'll see recreating
.
The advantage of this over just calling up --build
is that you can see the building-process first before you restart.
1: from the comments; down is not needed, you can just call up --build
. Down has some "down"-sides, including possible being destructive to your (volume-)data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With