mdornfe1
mdornfe1

Reputation: 2160

Is there a way to erase docker history?

When building an image I have to pass in credentials to get through a corporate proxy through a build-arg. These credentials are then visible through the docker history command. Is it possible to erase or redact my credentials from the build history?

Upvotes: 1

Views: 2249

Answers (2)

V-Q-A NGUYEN
V-Q-A NGUYEN

Reputation: 1697

First use the docker export command to prevent sensitive data from being shown with the history command. You need to start a container from an image first. Then we can export and import the container in one line:

docker export <CONTAINER ID> | docker import - some-image-name:latest

Then you can use some common Linux tricks to shrink Docker images. One simple trick is to clear the cache of the package manager:

# clean apt cache
apt-get clean

For details, this blog post seems to support the idea.

Upvotes: 0

Greg
Greg

Reputation: 23483

Using a multi-stage build, you can copy the build artifacts from the first stage into a new second stage. The second stage won't have the history of the first stage.

Upvotes: 2

Related Questions