Got : printf: write error: No space left on device
To check the current disk usage on CentOS 7, you can use the following commands:
df -h
The -h
flag makes the output human-readable.
du -sh /path/to/directory
Replace /path/to/directory
with the directory you want to check.
du -ah / | sort -rh | head -n 20
This command will list the top 20 largest files and directories starting from the root (/
).
When dealing with Docker images in a Minikube and GitLab CI/CD setup, managing disk space becomes crucial. Docker images can consume significant space, especially if not managed properly. Here are some best practices for managing Docker images to avoid running out of disk space:
docker system prune -a -f
docker image prune -a -f
docker image ls
command to list all images, and then remove older images using docker rmi <image_id>
.# First stage: build
FROM maven:3.6.3-jdk-8 as builder
WORKDIR /app
COPY . .
RUN mvn clean install
# Second stage: run
FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=builder /app/target/myapp.jar /app/myapp.jar
CMD ["java", "-jar", "/app/myapp.jar"]
.dockerignore
file to exclude unnecessary files and directories from the build context, reducing the image size..dockerignore
file:node_modules
target
*.log
cleanup:
stage: cleanup
script:
- docker image prune -a -f
only:
- schedules
Here's an example of a GitLab CI/CD pipeline that includes a cleanup job for Docker images:
stages:
- build
- test
- deploy
- cleanup
variables:
DOCKER_DRIVER: overlay2
cache:
paths:
- .m2/repository
- node_modules/
before_script:
- docker info
build:
stage: build
script:
- echo "Building Docker image..."
- docker build -t myapp:${CI_COMMIT_SHA} .
- docker tag myapp:${CI_COMMIT_SHA} myapp:latest
tags:
- docker
test:
stage: test
script:
- echo "Running tests..."
- docker run --rm myapp:${CI_COMMIT_SHA} ./run_tests.sh
tags:
- docker
deploy:
stage: deploy
script:
- echo "Deploying Docker image..."
- docker push myapp:${CI_COMMIT_SHA}
- docker push myapp:latest
tags:
- docker
environment:
name: production
url: https://your.production.url
cleanup:
stage: cleanup
script:
- echo "Cleaning up old Docker images..."
- docker image prune -a -f
tags:
- docker
only:
- schedules
Implement monitoring tools to track disk space usage and set alerts:
By following these best practices, you can effectively manage Docker images, ensuring your Minikube environment and GitLab CI/CD pipelines run smoothly without running out of disk space.
To show the disk usage of Docker images, you can use the docker system df
command, which provides a summary of Docker disk usage including images, containers, volumes, and the build cache.
Here’s how you can get detailed information on disk usage for Docker images:
docker system df
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
Running docker system df
will output something like this:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 10 5 2.33GB 1.76GB (75%)
Containers 5 3 850MB 850MB (100%)
Local Volumes 3 2 1.2GB 500MB (41%)
Build Cache 0 0 0B 0B
Running docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
will output something like this:
REPOSITORY TAG SIZE
myapp latest 500MB
myapp v1.0.0 500MB
nginx latest 133MB
alpine latest 5.59MB
docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"
docker inspect <image_id>
docker ps -a --format "table {{.ID}}\t{{.Image}}\t{{.Size}}"
To avoid excessive disk usage, regularly clean up unused Docker objects. You can use a cron job or schedule a job in your CI/CD pipeline to perform cleanup tasks.
Here's a sample cron job that prunes unused Docker objects weekly:
crontab -e
0 0 * * 0 docker system prune -a -f
This will run docker system prune -a -f
every Sunday at midnight.
By using these commands and best practices, you can effectively monitor and manage the disk usage of Docker images in your Minikube environment.