【英文】Docker容器内部使用宿主机的docker命令操作Docker

Preface

Docker containers operate Docker using the host machine’s docker command.

Modify the permissions of critical files

1
2
chown root:root /var/run/docker.sock
chmod o+rw /var/run/docker.sock

Map Docker critical files

/var/run/docker.sock: Map Docker runtime
/usr/bin/docker: Map Docker executable file
/etc/docker/daemon.json: Map Docker configuration, can be ignored if not available

1
2
3
4
5
6
7
8
version: "3.1"
services:
ubuntu:
image: ubuntu
container_name: ubuntu
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker

Start the container

  • Get interactive Shell through docker-compose

ubuntu: Container name

1
docker-compose run --rm ubuntu

Finished

References

Bilibili - Cloud Native Technology Architecture
Qastack - Adrenaline