问题原文
原帖链接 · Paul Gregoire · CC BY-SA 3.0
How do a prevent a user of my pre-built docker container from being able to access a shell within a running instance of that container? I have googled and read all the posts that are related to this scenario and have come up without a working solution. I am trying to prevent access to a given resource in the container, for the sake of this inquiry, let's say its a serial number in a configuration file. I am building upon the java:7 image which is based upon an ubuntu image.
To test your solution, do the following:
Create and run your docker container
Export your container
docker export [container name] | gzip -c > mycontainer.tar.gz
Import your container on an external system
gzip -dc mycontainer.tar.gz | docker import - [container name]
Run the container
Shell into the running container using any / all of the following methods:
docker exec -it [container name] bash
docker attach [container name]
docker run -ti --entrypoint=/bin/bash [container name]
[container name] is the name of your container
bash, dash, and sh are all valid shells
社区高分解答
原帖链接 · Dr.Knowitall · CC BY-SA 3.0
To add on to Jose's answer, another solution is to...
docker exec :id -it /bin/rm -R /bin/*
That gets rid of sh and any bin useful command in linux. I'm unsure what you'd do to get into the container at that point. Though I know that you might be able to use a memory debugger to get environment variables of the running container, but it makes it that much more annoying... I wonder if theres a way to lock down that memory in ring 0 and take away ssh access altogether to the host.
If anyone knows how to crack that, I would be interested in knowing how.
EDIT
You want to use docker secrets if you're protecting sensitive information. Check out:
https://docs.docker.com/engine/swarm/secrets/
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
