Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Franz Wong
Franz Wong

Posted on • Edited on

     

Access host's docker from container

We are going to access host's docker from container.

Container requires docker to be installed. (You can also installdocker-compose if you need)

FROM centos:7RUN set -eux; \    yum install -y sudo;# Install docker and docker-composeRUN set -eux; \    sudo curl -sSL https://get.docker.com/ | sh; \    sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose; \    sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen modeExit fullscreen mode

Just build the docker image as usual.

docker build -t franz/test .
Enter fullscreen modeExit fullscreen mode

We mount docker socket and passprivileged flag to get permission to run.

docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock --privileged --name test franz/test /bin/bash
Enter fullscreen modeExit fullscreen mode

You can trydocker ps to see if it is using thedocker in the host machine.

[root@5ef32b67b635 /]# docker psCONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES5ef32b67b635        franz/test          "/bin/bash"         3 seconds ago       Up 2 seconds                            test
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Hong Kong
  • Joined

More fromFranz Wong

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp