How to get going:
- Open a terminal in the root of the project
- Copy paste commands as desired
Normal version:
docker build -t example .
Extended version:
docker build -f Dockerfile.extended -t example2 .
dive example
# OR
dive example2
docker run --rm example
# OR
docker run --rm example2
This will use the defined CMD to be executed.
docker run --rm -it example /bin/bash
# OR
docker run --rm -it example2 /bin/bash
This overwrites/replaces the default CMD with /bin/bash
and gives an interactive shell (--interactive --tty
or in short -it
).
Note: To exit the shell: type exit
or CTRL + D.
Relevant option: -e <VAR_NAME>="<some-value>"
Example:
docker run --rm -e HELLO_WORLD="bye" example
Relevant option: -v <local-src-dir>:<container-dir>
Examples:
docker run --rm -it -v ./:/home/ugr/test example /bin/bash
# OR
docker run --rm -it -v ./:/home/ugr/test example2 /bin/bash
Relevant option:--net <network-name>
Example:
docker run --rm -it --net none example /bin/bash
Relevant option: -u <user>
Example:
docker run --rm -u root -it example2 /bin/bash
Relevant option: -w <container-dir>
Examples:
docker run --rm -w /root -it example /bin/bash
# OR
docker run --rm -w /root -it example2 /bin/bash
# Get all environment variables
env
# Echo the environment variable HELLO_WORLD (as set in the Dockerfile)
echo $HELLO_WORLD
# List files and directory in current directory (with permissions and owner)
ls -al
# List files and directory in current directory (with permissions and owner and group as id)
ls -aln
# Print current directory
pwd
# Change directory to `<path-to-directory>` (e.g. `/home`, `/`, `test`)
cd <path-to-directory>
# Print current user
whoami
# Get current user id mapping and groups
id