Rebuild a Single Docker Container
If you use Docker Compose to manage multiple containers, networking, etc. and need to rebuild a single service or container, here are a few commands that will help.
To rebuild a single service or container that was initially started Docker Compose, use the following command in your terminal:
docker-compose up -d --no-deps --build < service name >
| Command | Description |
|---|---|
| —build | Build new Docker images before starting containers |
| —force-recreate | Recreate containers even if their image and configuration have not changed |
| -d | Run containers in detached mode |
| —no-dep | Do not start linked services |
You can pass multiple service names.
docker-compose up -d --no-deps --build < service name 1 > < service name 2 >
Alternatively
If you want to stop, create, and start your containers you can use the following commands:
1) docker-compose stop < service name > // Stop running service
2) docker-compose rm < service name > // Remove service
3) Make any changes to configuration, files, etc.
4) docker-compose create < service name >
5) docker-compose start < service name >