Skip to main content

Docker Inside

Build Status PyPI

dockerinside is a Python (Python3 only) package that shall simplify running docker images as the current user similar to the way Jenkins awesome docker.inside() works. There are two main use-cases:

  • You want to easily share access between a container and your environment without having to manually modify the user id and group id of the files created by the running container.
  • You want to run dockerized GUI applications but share your home environment

You don't have to write a Dockerfile just to adapt to your environment (user id / group id). It is a much more elegant approach to adapt the environment during startup of the container on the fly as Jenkins does it.

Installation

Prerequisits:

  • Python3 installation (>= 3.6)
  • python3-venv is recommended to create a virtual environment

Install current stable version (preferably in a virtual environment):

    pip install git+https://github.com/boon-code/docker-inside.git

For convenience, dockerinside uses su-exec which is statically compiled using alpine and musl-c library. To build it, you have to run

    # use --auto-pull to download alpine image for compilation if it's not available
    docker-inside-setup --auto-pull

This will create a directory ~/.config/docker_inside/ and put a file named su-exec there. You can also compile su-exec and create the file structure yourself or not use it at all. If this file doesn't exist, su is used to switch user id which might cause problems with tty handling, so it's highly recommended to use su-exec.

Big thanks to Natanael Copa (ncopa) for sharing su-exec.

NO_README

If you experience problems related to packaging the README.md or related to setuptools you can disable this behavior using the environment variable NO_README (f.e. NO_README=1).

Usage

Basic

Running an ubuntu:16.04 container as current user with the home directory mounted:

    docker-inside -H ubuntu:16.04

which is roughly equivalent to running

    docker run --rm -ti --user "$(id -u)" -v "${HOME}:${HOME}" ubuntu:16.04

but does already add users and groups so you won't see I have no name! in your shell prompt.

Fake Home

You can also use a fake home directory

    mkdir -p /tmp/fake-home
    docker-inside --mount-as-home /tmp/fake-home ubuntu:16.04 -- echo "Hello, World" \>~/readme.txt
    #DockerInside : MainThread : INFO : Starting container: 59133ebeb3a3116999f66b4e302ba675a74f02ac83ae526704f2f4cdbd82ed5d
    #DockerInside : MainThread : INFO : Container 59133ebeb3a3116999f66b4e302ba675a74f02ac83ae526704f2f4cdbd82ed5d stopped
    cat /tmp/fake-home/readme.txt
    #Hello, World

Jenkins Debugging

Sometimes, I just quickly want to debug a problem on a failing Jenkins job which uses docker with lot's of bind mounts which is as simple as this:

    cd <WORKSPACE>
    docker-inside -v <first-mount>:<some-path> \
                  -v <second-mount>:<some-other-path> \
                  -v <WORKSPACE> \
                  -w <WORKSPACE> \
                  <IMAGE_TO_USE> \
                  [optional-command]

Additional Use-Cases

Please let me know I you need support for more options from original docker run command or have any other suggestions how to improve this package. Please also let me know if your Docker image is failing using this package and I will see if I can fix the issue. Adding users and groups is unfortunately quite different among distributions.

Related

I still use the package myself on a regular basis when using Docker. However, to avoid having to rely on work-arounds used in this script, podman is a simple and powerful replacement for Docker. podman handles user permissions and bind mounts in a sane way per default. Check it out!

Metadata

Release files for docker-inside 0.3.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docker-inside 0.3.18
File Size Uploaded
docker-inside-0.3.18.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docker-inside 0.3.18
File Interpreter ABI Platform
docker_inside-0.3.18-py3-none-any.whl Python 3 none any Details

Total release size: 30.4 kB

Release files / docker-inside-0.3.18.tar.gz

Download URL docker-inside-0.3.18.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
27aadb334e9cad2f23fc113db27c41782cef0f21d7dd9ee2b9a9207e8ac3c0ac
BLAKE2b-256 checksum
How to use checksums
3e90959c66507a6d42f5937cd859b98d5e4c230aacc3099ae80bde30078f2812
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / docker_inside-0.3.18-py3-none-any.whl

Download URL docker_inside-0.3.18-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b4806f46cffb97beec1ba890ee795aba140968602858d59f7640a18fc1a34b7
BLAKE2b-256 checksum
How to use checksums
7c14b8d6e5efd0fa32bb0bdf073dadf1ab632022bd498055c7a84ea3688de9b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.3.18 This release

2 release files

0.3.17

1 release file

0.3.16

1 release file

0.3.15

1 release file

0.3.14

1 release file

0.3.13

1 release file

0.3.12

1 release file

0.3.11

1 release file

0.3.10

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.4

2 release files

0.3.1

1 release file

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page