The setup you have now is probably acceptably secure. There's no way to hide or redact data from docker inspect
, but anyone who's capable of running docker inspect
can do a lot more damage if they're motivated.
The first rule of Docker security is that anyone who can run any docker
command at all can root the entire host. Docker doesn't have an internal permission system, the only security control is usually the permissions on the docker.sock
file. So if you can docker inspect
the container, you can run any docker
command; which means you can start a container; which means you can bind-mount any part of the host filesystem and get an interactive shell as root.
# Anyone who can
docker inspect the-container | grep PASSWORD
# could also
docker run --rm -v /opt/app:/opt/app -u root busybox \
cat /opt/app/docker-compose.yml
# to read the Compose file
# or, for that matter
docker run --rm -v /:/host -u root busybox \
vi /host/etc/shadow
# to reset host root's password and the system is theirs
There's an argument that passwords shouldn't be put in environment variables at all, independent of Docker. If you subscribe to this approach, and bind-mount the configuration files into containers, then they won't be visible to docker inspect
(but you could still docker exec
into the container to read them, among other paths).
Arguably the "best" approach is to have the container be able to connect to some sort of external secret storage at startup time to retrieve the credentials it needs, but this is a significant setup change in your application, and it still needs some way to authenticate to that secret storage.