Skip to content

Instantly share code, notes, and snippets.

@syedmhashim
Created May 10, 2023 09:03
Show Gist options
  • Save syedmhashim/b0071f15f53a588f498106b690b5c47d to your computer and use it in GitHub Desktop.
Save syedmhashim/b0071f15f53a588f498106b690b5c47d to your computer and use it in GitHub Desktop.
Run docker commands in a docker container with your current directory mounted into the container
version: "3.3"
services:
docker:
image: docker:20.10.16
restart: always
volumes:
- $PWD:/home/
environment:
- DOCKER_TLS_VERIFY=
- DOCKER_TLS_CERTDIR=
- ENV_MODE=local
- DOCKER_HOST=tcp://daemon:2375
entrypoint: "/bin/sh -c \"tail -f /dev/null\""
depends_on:
- daemon
daemon:
image: docker:20.10.16-dind
privileged: true
environment:
- DOCKER_TLS_VERIFY=
- DOCKER_TLS_CERTDIR=
@syedmhashim
Copy link
Author

syedmhashim commented May 10, 2023

You may want to add the following function to your .bashrc or .zshrc file:

  function run_in_docker() {
          docker-compose -f $PATH_TO_FILE/dind.docker-compose.yaml up -d
  }

Where you need to replace $PATH_TO_FILE with the actual path where the dind.docker-compose.yaml file is stored. Once this is done, you can run the follow the steps below to open your current working directory inside a docker container for debugging:

  1. run_in_docker
  2. docker ps -a.
    Note the name of the docker container.
  3. docker exec -it <container_name> sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment