datastack-net / dockerized Goto Github PK
View Code? Open in Web Editor NEWRun popular commandline tools within docker
License: MIT License
Run popular commandline tools within docker
License: MIT License
As a user, I would like to run commands like npm run serve
or mkdocs serve
without being required to manually map the port to the container.
This way, the commands work more like native commands, and it makes dockerized much more convenient.
Requirements:
-p <PORT>
when running dockerized
.npm run serve
and npm run lint
, using the same npm
command).Out of scope:
Possible solutions:
npm run serve
and npm run lint
HOST:application port
⇄ HOST:$RANDOM
⇄ CONTAINER:$RANDOM
⇄ CONTAINER:application port
mkdocs serve --dev-addr=0.0.0.0:8000
reveals that port 8000 should be opened.
--dev-addr=[^:]+:(?P<port>\d+)
com.dockerized.port
mkdocs.yml
npm run serve --env=production
using a different port)$PORT
to determine the port to run on.dockerized.env
per command
<command> foo $(date)
The script bin/dockerized
isn’t set up to be able to build for Apple Silicon. Modifying the architectures should probably include a detection for aarch64
arm64
, the arm64 / aarch64 target for GO.
https://github.com/datastack-net/dockerized/blob/master/bin/dockerized#L55-L63
I have noticed that on my Windows 10 laptop when I use WSL and attempt to override the Linux HOME environment variable, the overriding of the value partially works.
The reason that I am trying to do this is so my Windows home .ssh configuration is shared between the CMD and WSL environments, while using the same dockerized docker-compose.yaml file.
In Windows 10, there is no HOME environments variable, instead there is a HOMEPATH.
In WSL there is already a HOME environments variable that points to the Linux /home/<wsl user> folder. I would like to override this to point to the Windows 10 HOMEPATH environments variable instead.
NOTE: Below is a working version as I am using the HOMEPATH environment variable in the docker-compose.yml file. When I change HOMEPATH to HOME, it then fails.
Here is my setup:
# C:\Users\<user>\dockerized.env (Command Prompt)
HOME=${HOMEPATH}
COMPOSE_FILE="${COMPOSE_FILE};${HOME}/.dockerized/docker-compose.yml"
# /home/<wsl user>/dockerized.env (WSL2)
HOMEPATH=/mnt/c/Users/<user>
HOME=${HOMEPATH}
COMPOSE_FILE="${COMPOSE_FILE};${HOME}/.dockerized/docker-compose.yml"
# C:\Users\<user>\.dockerized\docker-compose.yml
# /mnt/c/Users/<user>/.dockerized/docker-compose.yml
version: "3"
services:
dev:
image: "my-project-build-env"
build:
context: ${HOMEPATH:-.}/.dockerized/apps/my-project-build-env
stdin_open: true # docker run -i
tty: true # docker run -t
entrypoint: [ "/init.sh", "/bin/bash" ]
volumes:
- ${HOMEPATH:-.}/.m2:/root/.m2
- ${HOMEPATH:-.}/.ssh:/dockerized/host/home/.ssh
- ${HOMEPATH:-.}/.dockerized/apps/my-project-build-env/init.sh:/init.sh
Here is the successful WSL debug logs when using HOMEPATH:
> dockerized -v dev
Dockerized root: /mnt/c/Tools/dockerized
Loading: '/mnt/c/Tools/dockerized/.env'
Loading: '/home/<wsl user>/dockerized.env'
Compose files: /mnt/c/Tools/dockerized/docker-compose.yml, /mnt/c/Users/<user>/.dockerized/docker-compose.yml
# My dockerized 'dev' service works.
Here is the failing WSL debug logs when using HOME:
> dockerized -v dev
Dockerized root: /mnt/c/Tools/dockerized
Loading: '/mnt/c/Tools/dockerized/.env'
Loading: '/home/<wsl user>/dockerized.env'
Compose files: /mnt/c/Tools/dockerized/docker-compose.yml, /mnt/c/Users/<user>/.dockerized/docker-compose.yml
# My dockerized 'dev' service fails.
The above debug logs are exactly the same.
Based on the compose files specified above, I generated a docker-compose command:
> docker-compose -f /mnt/c/Tools/dockerized/docker-compose.yml -f /mnt/c/Users/<user>/.dockerized/docker-compose.yml config
ERROR: build path /home/<wsl user>/.dockerized/apps/my-project-build-env either does not exist, is not accessible, or is not a valid URL.
When I run:
> HOME=/mnt/c/Users/<user> docker-compose -f /mnt/c/Tools/dockerized/docker-compose.yml -f /mnt/c/Users/<user>/.dockerized/docker-compose.yml config
# It succeedds and shows the complete docker-compose file which was assembled from the 2 yaml files.
Based on this, I think that the system environment variables aren't being overridden, or the system variables are being applied on top of the other .env and dockerized.env variables.
Would it be possible to create an internal dockerized 'config' service so that it will show the complete docker compose file and service configuration, like the 'docker-compose config' does?
Hi,
When the docker-compose command is run it will use the docker-compose.yml and docker-compose.override.yml file, and combine their configurations.
Could this be added to this projects?
This would allow me to have my own docker-compose.override.yml file which would be combined with the default configuration of dockerized, and allowing me to easily upgrade without worrying about overwriting my own local changes.
Most mysterious bug ever.
Expected:
dockerized --shell <command> -c env
should print the current environmentActual:
In some specific conditions, there is no output from the container at all, and dockerized just exits.
Run bin/dockerized -v --shell perl -c env | tee ~/shell.log
Dockerized root: /home/runner/work/dockerized/dockerized
Loading: '/home/runner/work/dockerized/dockerized/.env'
Compose files: /home/runner/work/dockerized/dockerized/docker-compose.yml
Setting up shell in container for perl...
Entrypoint: [/bin/bash]
Command: [-c env]
Preparing compose environment...
Network dockerized_default Creating
Network dockerized_default Created
Volume "dockerized_node_modules" Creating
Volume "dockerized_node_modules" Created
Volume "dockerized_python_modules" Creating
Volume "dockerized_python_modules" Created
Volume "dockerized_pip_cache" Creating
Volume "dockerized_pip_cache" Created
Volume "dockerized_go_cache" Creating
Volume "dockerized_go_cache" Created
Volume "dockerized_home" Creating
Volume "dockerized_home" Created
Running one-off container...
Container exited with code 0.
Observations:
bash
. Switching to sh
for --shell
fixes the bug.sh
is not a universal fix. rustc
uses sh
and still doesn't work.docker system prune -af
won't help to reproduce it, running without a tty. (true | dockerized --shell perl -c env | cat
)docker-compose run --rm <command>
always seems to work.Hypothese (and motivation):
docker-compose run
and dockerized
echo helloworld
the first time didn't fix perl, but disabling TTY did. So TTY is involved.env
commandExcluded causes:
dockerized --pull
. Running this before the shell test doesn't make a difference.Instead of
NODE_VERSION=15.0.0 dockerized node
how about
dockerized node:15
Just a suggestion!
How to use dockerized Go when I need to specify $GOROOT and $GOPATH for linting in my IDE
https://github.com/fatih/vim-go/blob/421563081bddaec1f7a66710b5c8ee305724d2a9/doc/vim-go.txt#L123-L126
https://www.jetbrains.com/help/go/configuring-goroot-and-gopath.html
Hi,
I stumbled over this wonderful project. Really like it so far, thanks :)
Looking at the last update beeing in 2022 I was wondering, if this is still maintained / improved?
Regards,
Daniel
I'm using "dockerized --build run ..."
As far as I understand I'm currently not able to pass some "--build" parameters to this command (?)
https://docs.docker.com/engine/reference/commandline/compose_build/
For example --no-cache and --pull would be quite nice for my workflow.As far as I understand I'm currently not able to do an "only-build" execution instead of
"build + run" (?)
I have a local base image as dependency for my final image.
If I execute "dockerized --build run ..." this will (obviously) be executed, while I would only need it to be built.
Workaround is to use "docker compose build ...." instead, which leads to a mix of "dockerized" and "docker compose" - commands in my workflow.How do you feel about these points? :)
Regards,
Daniel
Originally posted by @danielrolfes2307 in #50 (comment)
Currently there are almost no features, and they are implemented twice, once in Bash and once in Powershell.
This is important to avoid any dependencies beyond Docker, and to make it cross-platform.
In the long term, implementing everything twice in languages like Bash and Powershell may not be sustainable.
How should Dockerized be implemented, to support more features, keep it cross-platform, and make it easy to contribute and maintain?
Here are all the options I've thought of, happy to hear your thoughts.
dockerized
cannot be used everywhere.dockerized
with go get
.bin/dockerized.py
)
docker start
. On my super fast Windows system docker start
takes 1.5 seconds. Dockerized would become unbearably slow.ℹ️ E.g. Include
dockerized.go
, launch agolang
container that compiles an .exe for Windows, extract it, and run it on the host. This can be done for all platforms
Let
dockerized
figure out the platform, download the executable into a local directory and then continue in the other language
npm install
would need to run on the host, as in some cases precompiled binaries are included.❯ bin/dockerized node:16.14 --version
[+] Running 6/0
⠿ Network dockerized_default Created 0.0s
⠿ Volume "dockerized_pip_cache" Created 0.0s
⠿ Volume "dockerized_go_cache" Created 0.0s
⠿ Volume "dockerized_home" Created 0.0s
⠿ Volume "dockerized_node_modules" Created 0.0s
⠿ Volume "dockerized_python_modules" Created 0.0s
[+] Running 10/10
⠿ node Pulled 69.2s
⠿ c732c99090fe Pull complete 42.9s
⠿ 26cef8e19215 Pull complete 43.1s
⠿ 741a7b3bab3c Pull complete 43.3s
⠿ 66bff08cf973 Pull complete 44.9s
⠿ 3d35ac8f6f1a Pull complete 66.9s
⠿ a25eb52b374a Pull complete 67.0s
⠿ bc98bafd2f98 Pull complete 67.9s
⠿ 82c51e978386 Pull complete 68.0s
⠿ 24dba3274ff0 Pull complete 68.0s
Error response from daemon: error while creating mount source path '/Users/austin/.dockerized/apps/node': chown /Users/austin/.dockerized/apps/node: permission denied
Second run outputs the expected version (v16.14.2
).
Trying with dockerized python:3 --version
results in a similar error on the first run:
❯ bin/dockerized python:3 --version
[+] Running 10/10
⠿ python Pulled 7.5s
⠿ fa223d8c149d Already exists 0.0s
⠿ 17ffbd2ab159 Already exists 0.0s
⠿ a3953e76cee2 Already exists 0.0s
⠿ 6f906570592f Already exists 0.0s
⠿ c478f6a18a39 Already exists 0.0s
⠿ 965f10264bda Pull complete 3.1s
⠿ fae4e8c73329 Pull complete 6.1s
⠿ 2ac2661d4813 Pull complete 6.2s
⠿ 993092bb086d Pull complete 6.3s
Error response from daemon: error while creating mount source path '/Users/austin/.dockerized/apps/python': chown /Users/austin/.dockerized/apps/python: permission denied
Description
Files created by dockerized
commands are not owned by the host's current user, but for example root
.
This makes dockerized hard to use on unix systems, as generated files cannot be modified by the user.
It is also inconsistent with the design goal that Dockerized commands should behave the same as native commands.
Reproduction
> dockerized bash -c 'touch foo'
ls -l foo
-rw-r--r-- 1 root root 0 Apr 22 10:57 foo
Possible Solutions
These are all ideas I could come up with so far. Your thoughts and suggestions are welcome.
The goal is to find a solution with no blockers (:x:), and remove ❔ by doing more research.
root
(which is the default on most images) may become inaccessible, e.g. /root
~
will point to /
)/root
npm run
which continuously updates files. Permissions won't be fixed until the program finishes.docker
fix the permissions. I.e. run dockerized alpine chown $(id -u):$(id -g) $FILES
(this works)
docker
or another user.❯ bin/dockerized --compile=docker
Compiling dockerized...
go: downloading github.com/docker/compose/v2 v2.3.3
go: downloading github.com/hashicorp/go-version v1.3.0
go: downloading github.com/mitchellh/mapstructure v1.4.3
go: downloading github.com/opencontainers/go-digest v1.0.0
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/imdario/mergo v0.3.12
go: downloading github.com/docker/docker v20.10.3-0.20220121014307-40bb9831756f+incompatible
go: downloading github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/theupdateframework/notary v0.6.1
go: downloading github.com/buger/goterm v1.0.4
go: downloading github.com/containerd/containerd v1.6.1
go: downloading github.com/docker/buildx v0.7.1
go: downloading github.com/hashicorp/go-multierror v1.1.1
go: downloading github.com/moby/buildkit v0.9.1-0.20211019185819-8778943ac3da
go: downloading github.com/opencontainers/image-spec v1.0.2
go: downloading github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b
go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
go: downloading golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
go: downloading github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c
go: downloading github.com/morikuni/aec v1.0.0
go: downloading github.com/containerd/console v1.0.3
go: downloading github.com/AlecAivazis/survey/v2 v2.3.2
go: downloading github.com/golang/mock v1.6.0
go: downloading google.golang.org/grpc v1.45.0
go: downloading github.com/klauspost/compress v1.13.5
go: downloading github.com/opencontainers/runc v1.1.0
go: downloading golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
go: downloading github.com/moby/sys/signal v0.6.0
go: downloading github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
go: downloading github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412
go: downloading golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
go: downloading github.com/moby/sys/symlink v0.2.0
go: downloading golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
go: downloading github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading github.com/docker/go-metrics v0.0.1
go: downloading github.com/prometheus/client_golang v1.11.0
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/prompt/prompt.go:20:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/progress/writer.go:24:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build_buildkit.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:27:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:28:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:29:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/prompt/prompt_mock.go:10:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build_classic.go:40:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/api/labels.go:22:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/archive/archive.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:32:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/command/image/build/dockerignore.go:8:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:33:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:34:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/jsonmessage/jsonmessage.go:11:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/jsonmessage/jsonmessage.go:12:2: zip: not a valid zip file
/go/pkg/mod/github.com/distribution/distribution/[email protected]/digestset/set.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/api/types/registry/registry.go:7:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/idtools/idtools_unix.go:17:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]/counter.go:3:8: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]/handler.go:7:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]/sockets/proxy.go:9:2: zip: not a valid zip file
/go/pkg/mod/golang.org/x/[email protected]/ssh/terminal/terminal.go:14:2: zip: not a valid zip file
/go/pkg/mod/github.com/containerd/[email protected]/errdefs/grpc.go:24:2: zip: not a valid zip file
/go/pkg/mod/github.com/containerd/[email protected]/errdefs/grpc.go:25:2: zip: not a valid zip file
Failed to compile dockerized
Compiling on the host works just fine.
The latest release v2.15.0 doesn't contain build artifacts, missing /bin folder.
Lock default versions to specific image hashes, to make command upgrades explicit.
Why:
Last week all major official dockerhub images were updated and existing tags replaced. This has broken the --shell
integration tests for several commands.
For example, golang:1.16
now uses alpine3.15
, whereas before, it may have been 3.14
or even a different linux distro (it's not actually possible to know what was used before).
This reveals that specifying versions (or even tags) is not enough to guarantee reproducibility, i.e. dockerized may work well one day, and be broken another. Differences between systems may occur, depending on which image was present locally for a specific tag.
Functional requirements
.env
file is still readable and intuitive, i.e. GO_VERSION=1.17.8
and not GO_VERSION=f837w389875t0438r
Technical implementation
Todo.
Out of scope
These features can be considered for a future iteration:
dockerized go:1.16
will then lock go 1.16 to a particular digest, 'forever')A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.