Docker

1 ARG and ENV

From Dockerfile reference:

The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag.

The ENV instruction sets the environment variable <key> to the value <value>.
The environment variables set using ENV will persist when a container is run from the resulting image.

So if you need build-time customization, ARG is your best choice. If you need run-time customization (to run the same image with different settings), ENV is well-suited.

If I want to add let’s say 20 (a random number) of extensions or any other feature that can be enable|disable

Given the number of combinations involved, using ENV to set those features at runtime is best here.

But you can combine both by:

building an image with a specific ARG using that ARG as an ENV

That is, with a Dockerfile including:

ARG var
ENV var=${var}

You can then either build an image with a specific var value at build-time (docker build –build-arg var=xxx), or run a container with a specific runtime value (docker run -e var=yyy)

2 Find host ip in mac and linux

$ ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1

3 Debug existed docker container

$ docker ps -a
$ docker inspect 1f91b495fc38 -f '{{json .State}}'
$ docker logs 1f91b495fc38

4 Debug JAVA

Looking Inside a JVM: -XX:+PrintFlagsFinal


© 2015-2020 tendant