DEV Community

Franz Wong
Franz Wong

Posted on • Edited on

3

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 install docker-compose if you need)

FROM centos:7

RUN set -eux; \
    yum install -y sudo;

# Install docker and docker-compose
RUN 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 mode Exit fullscreen mode

Just build the docker image as usual.

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

We mount docker socket and pass privileged 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 mode Exit fullscreen mode

You can try docker ps to see if it is using the docker in the host machine.

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more