This write-up will demonstrate how to add the “–no-cache” option to the “docker-compose build” command.
How to Add the “–no-cache” Option to the “docker-compose build” Command?
However, in some cases, users must rebuild the fresh Docker image through the “docker-compose build” command. For this purpose, the “–no-cache” option is utilized to avoid the previous image cache and build a new image completely. Look at the provided instructions to add the “–no-cache” option to the “docker-compose build” command.
Step 1: Create “docker-compose.yml” File
First, create a simple “docker-compose.yml” file to containerize and configure the Golang application:
services:
web:
build: .
ports:
- "8080:8080"
golang:
image: "golang"
Step 2: Create and Start Container
To automatically build and execute the Docker image and Docker container, utilize the “docker-compose up” command:
The output indicates that the “golangapp-golang-1” container is created and started:
Open the browser and navigate to the specified port to verify if the service is executed. In our case, we navigate towards the “localhost:8080”:
Next, forcefully stop the container by utilizing the “CTRL+C” key:
Step 3: Modify “docker-compose.yml” File
Make modifications to the “docker-compose.yml” file to create the Docker image. For instance, we have modified the image name from “golang” to “golang:alpine”:
Step 4: Build docker-compose Using “–no-cache” Option
Now, rebuild the image without using the cache of the previous image. For this purpose, use the “docker-compose build –no-cache” command. The “–no-cache” option is used to avoid using a cache of the previous build while creating a new image:
Step 5: Recreate and Start Container
Lastly, again utilize the “docker-compose up” command to recreate and start the Docker container:
It can be observed that we have successfully recreated a container and fresh image using the “–no-cache” option.
Conclusion
The “–no-cache” option is used with the “docker-compose build” command to rebuild the fresh image by avoiding the cache of the previous image. To use the “–no-option” option, utilize the “docker-compose build –no-cache” command. This write-up has demonstrated how to add a “–no-cache” option to the “docker-compose build” command.
from https://ift.tt/rUj8H6k
0 Comments