Running commands on an image
$ docker run -it --entrypoint sh [imageId]
Remove all images and containers
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
source:
Docker container sha value
docker inspect --format='{{index .RepoDigests 0}}' <docker-image>
Remove all images with no tag
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 8ad635cb0348 22 hours ago 252.7 MB
<none> <none> 2ae831215dd7 40 hours ago 252.7 MB
To remove the images that have no tag, e.g.
docker rmi $(docker images | grep none | awk '{print $3}')
Run an image that was failing
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage 1.0.1 bafaeb0cf52a 12 minutes ago 180MB
$ docker run -it --entrypoint sh bafaeb0cf52a
Dockerfile
pulling an image using the sha
docker pull myimage@sha256:0ecb2ad60
Finding the sha256
docker inspect --format='{{index .RepoDigests 0}}' $IMAGE
Multi-stage builds
## https://quarkus.io/guides/building-native-image#creating-a-container-with-a-multi-stage-docker-build
## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/centos-quarkus-maven:19.2.1 AS build
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app
USER root
RUN chown -R quarkus /usr/src/app
USER quarkus
RUN mvn -f /usr/src/app/pom.xml -Pnative clean package
## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY --from=build /usr/src/app/target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
mount maven repository
on the command line:
export DOCKER_BUILDKIT=1
In the Dockerfile, as the first line
# syntax=docker/dockerfile:experimental
In the Dockerfile, in the mvn run command
RUN --mount=type=cache,target=/root/.m2 \
mvn --batch-mode -f /usr/src/app/pom.xml clean package
This will look like
Heap dumps from java
Use jattach
apk add --no-cache jattach --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/
Command to use
jattach 1 jcmd "GC.heap_dump /heap.hprof"