docker how do I make host scripts available inside a container

I am working with a kalilinux-based docker container (dnraikes/kali-net).
I am developing some proprietary scripts to run various security tools against our in-house servers so I don’t want to embed the scripts inside the docker image using either the COPY or ADD commands in my Dockerfile.

My scripts are in ~/scripts on the docker host.
when I run the docker container with the command:

  • Docker can't find a script that I COPY to an image when I try to invoke it twice via / && / (but once works!)
  • Shared library in containers
  • Automatic building and installing Packages from AUR for Arch Linux inside Docker with yaourt and >makepkg-4.2.0
  • docker build of Dockerfile fails
  • Running SystemTap inside an unprivileged docker container
  • ssh executing nsenter as remote command with interactive shell in golang to debug docker container
  • $ docker run -it -v /opt/scripts:~/scripts dnraikes/kali-net /bin/bash

    Once inside the container, if I switch to /opt there is no scripts folder.

    Also, any results from the scripts must be visible on the docker host after the container has been either killed or stopped.

    What am I doing wrong.

  • Overriding inherited CMD in Dockerfile does not always work?
  • Connect to mysql inside docker
  • Connecting to remote activemq instance running on docker container
  • Starting Xserver in Docker Ubuntu container
  • What is the best way to manage cert/key for Docker containers that must talk TLS
  • How to create autostart services in Docker container?
  • One Solution collect form web for “docker how do I make host scripts available inside a container”

    Try switching the directory locations like this:

    $ docker run -it -v /home/<username>/scripts:/opt/scripts dnraikes/kali-net /bin/bash

    From the documentation on volumes, -v takes [host-src]:[container-dest].

    Also note that host-src must be an absolute path so replace ~/scripts by /home/<username>/scripts or the full path to your scripts directory.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.