Skip to content

Instantly share code, notes, and snippets.

View rkuzsma's full-sized avatar

Rich Kuzsma rkuzsma

View GitHub Profile
@rkuzsma
rkuzsma / add_docker_to_etc_hosts.sh
Created April 9, 2016 22:07
Add (or replace) an entry called "dockermachine" in /etc/hosts that points to your local "docker-machine ip" so you can use http://dockermachine/
#!/bin/bash
# Add (or replace) an entry called "dockermachine" in /etc/hosts that points to
# your local "docker-machine ip" so you can use http://dockermachine/
eval $(docker-machine env)
readonly DOCKER_HOST_NAME="dockermachine"
readonly HOSTS_FILE="/etc/hosts"
readonly TMPFILE=$(mktemp)
readonly DOCKER_HOST_IP=$(docker-machine ip)
readonly DOCKER_HOST_ENTRY="$DOCKER_HOST_IP $DOCKER_HOST_NAME"
echo "Adding '$DOCKER_HOST_IP $DOCKER_HOST_NAME' entry to '$HOSTS_FILE' so you can use http://$DOCKER_HOST_NAME URLs for testing"
@rkuzsma
rkuzsma / gist:b9a0e342c56479f5e58d654b1341f01e
Last active May 18, 2024 15:40
Example Kubernetes yaml to pull a private DockerHub image
Step by step how to pull a private DockerHub hosted image in a Kubernetes YML.
export DOCKER_REGISTRY_SERVER=https://index.docker.io/v1/
export DOCKER_USER=Type your dockerhub username, same as when you `docker login`
export DOCKER_EMAIL=Type your dockerhub email, same as when you `docker login`
export DOCKER_PASSWORD=Type your dockerhub pw, same as when you `docker login`
kubectl create secret docker-registry myregistrykey \
--docker-server=$DOCKER_REGISTRY_SERVER \
--docker-username=$DOCKER_USER \
@rkuzsma
rkuzsma / docker-bash-completion.md
Last active November 18, 2023 09:11
How to configure Bash Completion on Mac for Docker and Docker-Compose

How to configure Bash Completion on Mac for Docker and Docker-Compose

Copied from the official Docker-for-mac documentation (thanks Brett for the updated doc pointer):

Install shell completion

Docker Desktop for Mac comes with scripts to enable completion for the docker, docker-machine, and docker-compose commands. The completion scripts may be found inside Docker.app, in the Contents/Resources/etc/ directory and can be installed both in Bash and Zsh.

Bash

Bash has built-in support for completion To activate completion for Docker commands, these files need to be copied or symlinked to your bash_completion.d/ directory. For example, if you installed bash via Homebrew:

@rkuzsma
rkuzsma / DockerCompose.java
Created December 30, 2016 03:52
Utility for launching local containers via docker-compose.
public class DockerCompose {
private final File dockerSrc;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public DockerCompose(String dockerSrcDir) {
dockerSrc = new File(dockerSrcDir);
if (!dockerSrc.exists()) {
throw new RuntimeException("Docker source path does not exist: " + dockerSrcDir);
}
logger.info("Docker source path: " + dockerSrc.getAbsolutePath());
}
@rkuzsma
rkuzsma / WaitFor.java
Created December 30, 2016 03:54
Java utility class to wait for ports and URL responses to be available
/**
* General utilities to wait for ports and URL responses to be available.
* Especially useful when waiting for container services to be fully "up".
*/
public class WaitFor {
private static final Logger logger = LoggerFactory.getLogger(WaitFor.class.getClass());
public static void waitForPort(String hostname, int port, long timeoutMs) {
logger.info("Waiting for port " + port);
@rkuzsma
rkuzsma / store-secrets.md
Created December 30, 2016 23:48
Poor-man's secure ENV variable storage using GPG

Store the secrets on a local machine:

mkdir -p ~/.secrets
touch ~/.secrets/my_secrets
chmod 600 ~/.secrets/my_secrets
cat << EOF | gpg -c -o ~/.secrets/my_secrets
export SOME_SECRET_VARIABLE=some value
export ANOTHER_SECRET_VARIABLE=another value
EOF
@rkuzsma
rkuzsma / get-k8s-node-ip-addresses.sh
Created January 5, 2017 03:33
Get external IP address of Kubernetes nodes
#!/bin/bash
kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\"ExternalIP\"\)].address}
@rkuzsma
rkuzsma / Dockerfile
Created April 1, 2017 21:53
Demonstrate failed attempt to build and run Jamvm with OpenJDK 8 inside Docker
FROM openjdk:8
# Download jamvm from source and apply this patch to src/classlib/openjdk/natives.c:
# https://sourceforge.net/u/tdaitx/jamvm/ci/f342a84116edfe28ab75ebfa17fcf929bafb02c1/tree/src/classlib/openjdk/natives.c?diff=236f9d849cf52faeb150a6cd5ba6fbeb61bd2f1f
RUN apt-get update -qq && apt-get install -y \
vim build-essential zlib1g-dev \
openjdk-8-jre-jamvm libtool autoconf automake
RUN git clone https://git.code.sf.net/p/jamvm/code jamvm-code
@rkuzsma
rkuzsma / top-cpu-process.sh
Created June 12, 2017 00:37
Bash script to fetch and sort the top CPU consuming process, displaying a concatenated form of the process startup command line arguments
# The sed expression is intended to replace this:
# %CPU %MEM COMMAND
# 0.0 0.1 some really really really long process args
# with this:
# %CPU %MEM COMMAND
# 0.0 0.1 some reall...ocess args
# In the sed regex:
# [^[:space:]]* means "a sequence non-whitespace characters"
# \s* means "a sequence of whitespace characters"
# The sed regex matches the first and last 10 characters of the process args,
@rkuzsma
rkuzsma / time_unit.rb
Last active July 24, 2017 02:46
TimeUnit helper written in Ruby to convert time expressions with a unit to milliseconds. e.g. 1m -> 60_000, 60s -> 60_000, 5000ms -> 5, 10s -> 10_000
# Created under Apache 2.0 License.
# Author: Rich Kuzsma
# Date: July 23, 2017
# Convert time duration strings like "10s" into milliseconds
module TimeUnit
UNITS_IN_MS = {
'd' => 86_400_000,
'h' => 3_600_000,
'm' => 60_000,