This image is used to create a portable development environment.
391
This is the repo that contains the code to build the dev-env Docker container. The main purpose of this docker container is to create a portable development environment so that no software needs to be installed on a (new) work computer. Also, the developer can then use an operating system of choise.
This Docker Image can be found on the Docker Hub at https://hub.docker.com/r/novinem/dev-env. To use this docker image, you'll only need to install Docker (dekstop), and set the following bash alias in:
nano ~/.bash_aliases
alias devenv='docker run -it --rm -e GIT_USER_NAME="<your_name_here>" -e GIT_USER_EMAIL="<your_email_here>" -v ~/.ssh:/home/node/.ssh:ro -v $PWD:/app -w /app novinem/dev-env'
Now, we only need to 'save' the changes by entering the following command: source ~/.bash_aliases.
Congratulations!
You can now use the dev-env with commands like: devenv npm install @scope/package-name or devenv composer require package/name.
While the alias above is the only alias you'll need to get started, it's cumbersome to type 'devenv' in front of every command. That's why we suggest to also include the following aliases in:
nano ~/.bash_aliases
alias node='devenv node'
alias npm='devenv npm'
alias npx='devenv npx'
alias git='devenv git'
alias php='devenv php'
alias composer='devenv composer'
alias laravel='devenv laravel'
The simple aliases above work correctly for most use cases. However, sometimes you'll want to pass extra docker options for binding a custom volume or simply to set a environment variable. In those cases, you could just use the 'docker run' command directly to pass in your custom values. However, there is an easier way!
For these use cases, we developed a more advanced version of the 'devenv' alias above.
Pay Attention! If you want to use this more advanced version, please make sure to remove the previously created alias first. Then, you can add the advanced 'devenv' function to:
nano ~/.bash_aliases
function devenv {
# Config variables
local email="<your_email_here>"
local name="<your_name_here>"
# Runtime variables
local runtime_args=()
local command_args=()
local image_name="novinem/dev-env"
local verbose=false # Flag to control echoing the Docker command
# Persistent storage file for runtime_args
local devenv_file=".devenv"
# Load runtime_args from persistent storage if available
if [[ -f "$devenv_file" ]]; then
# Read the entire content of .devenv as a single string and append to runtime_args
runtime_args+=($(cat "$devenv_file"))
fi
# Parse CLI arguments
while [[ $# -gt 0 ]]; do
if [[ "$1" == "verbose" ]]; then
verbose=true
shift
else
command_args+=("$1")
shift
fi
done
# Construct the Docker command
local docker_command=(
docker run -it --rm
-e GIT_USER_NAME="${name}"
-e GIT_USER_EMAIL="${email}"
-v ~/.ssh:/home/node/.ssh:ro
-v "$PWD:/app"
-w /app
"${runtime_args[@]}"
"$image_name"
"${command_args[@]}"
)
# Optionally echo the Docker command
if $verbose; then
echo "-------- COMMAND --------"
echo "${docker_command[@]}"
echo "------- DOCKER RUN -------"
fi
# Execute the Docker command
"${docker_command[@]}"
}
Why would you use the advanced version above? Let's say you want to develop a Laravel Package that is on your local PC. Normally, you would like to include that local package in your main Laravel project by including it in the repositories section of composer.json, like this:
....
"repositories": {
"dev-package": {
"type": "path",
"url": "/home/user/laravel-package-repository",
"options": {
"symlink": true
}
}
}
However, in this case, you can't just use the regular 'devenv' alias by running: devenv composer require vendor/laravel-package-repository. That's becase the URL (/home/user/laravel-package-repository) will not be not found by composer inside the devenv container. For this, you'll want to add another bind mount in docker (in the exact same location) so that composer could find that URL.
The 'devenv' function will allow you to do just that! It reads the content of a .devenv file in the current working directory and passes those contents to the 'docker run' part of the command.
Contents of .devenv:
-v /home/user/laravel-package-repository:/home/user/laravel-package-repository
Command:
devenv composer require vendor/laravel-package-repository
Explanation:
In this example, the folder (/home/user/laravel-package-repository) gets mounted inside the container at runtime.
Contents of .devenv:
-e TEST=true
-e REASON=because
Command:
devenv php -v
Explanation:
In this example, both environment variables gets set inside the container at runtime.
Contents of .devenv:
-e TEST=true -e REASON=because
Command:
devenv verbose php -v
Explanation:
This example is the same as the example above. Only now, we added the 'verbose' argument right after the 'devenv' call. This will print the actual command that gets used in plain text (for debugging purposes). The 'verbose' argument a reserved argument that must be placed before all other arguments!
This image works best when setting the aliases (or the advanced function) above. Those make sure to mount the current working directory in the right location inside the container to work with. Also, the alias mounts your own .ssh folder into the .ssh folder inside the container so you can use all you own SSH Keys (with GIT for example). As of now, this image has these features built in that can manipulate your working directory:
Features include:
git ac = !git add . && git commit -mgit amend = git commit --amendgit lg = git log --oneline --decorate --all --reversegit s = status -sbcommitlint. (this makes it easy to add automatic versioning and automatic generation of the changelog by implementing semantic-release in CI)Features include:
Features include:
Content type
Image
Digest
sha256:a8ef8c037…
Size
216.2 MB
Last updated
over 1 year ago
docker pull novinem/dev-env