Docker on Windows tips & tricks

Just some tips & tricks on Docker on Windows I documented for myself.

Location of Docker daemon logs

The Docker daemon logs can be found in the following location.

C:\ProgramData\Docker

By default C:\ProgramData is hidden in Explorer, you need to make it visible in the options (File -> Change folder and search options, select tab View, select the option ‘Show hidden files, folders and drives’ under ‘Hidden files and folders’).

Change folder and search options

Advertisements

Docker commands tips & tricks

Just some Docker commands tips & tricks I documented for myself.

Misc

Start interactive shell in Alpine image

Alpine uses the ash shell instead of the bash shell. This by the way also overrules the default CMD in the image.

$ docker run -it --entrypoint=/bin/ash image-id

Connect to a running container

What if you started a shell in the background and you want to see the stdout and stderr output? Connect to the running container.

$ docker attach container-id

Connect to a running container with an interactive shell

So what if you want to connect to a running container and inspect its contents? Just attach and start an interactive shell 🙂

$ docker exec -it container-id /bin/ash

Inspect image, volume or running container

It can be handy to inspect the settings of images, volumes or running containers. To do this use the following commands.

docker image inspect image-id
docker volume inspect volume-id
docker container inspect container-id

Build

Traditionally, the Dockerfile is called Dockerfile and located in the root of the context directory. You use the -f flag with docker build to point to a Dockerfile anywhere in your file system.

IMPORTANT when pointing to a Dockerfile not located in the context directory, you must add a period (.) at the end of the statement.

$ docker build -t my-label -f /path/to/a/Dockerfile .

Volumes

Volumes make it possible to persist data between container restarts and share data between containers.

Create a volume.

$ docker volume create logs

List files in a volume.

$ docker run -it --rm -v logs:/logs alpine ls -l /logs

Display the contents of a file in a volume.

$ docker run -it --rm -v logs:/logs alpine cat /logs/access.log

Interactive access to the files in a volume.

$ docker container run -ti -v logs:/logs alpine sh -c 'cd /logs; exec "${SHELL:-sh}'

Using tail with -f option to view changes to the contents of a file in realtime.

$ docker run -it --rm -v logs:/logs alpine tail -f -n 25 /logs/access.log

Finding out the size of directories in Linux

Do you want to know the size of a directory in Linux? Use the du command.

du -sh

Explanation

The du command estimates the space used by a directory.

The options -sh are (from man du):

  -s, --summarize
         display only a total for each argument

  -h, --human-readable
         print sizes in human readable format (e.g., 1K 234M 2G)

To check more than one directory and get the total size of those directories, use

du -sch *

What does the extra option mean?

  -c, --total
         produce a grand total

Include hidden files?

du -sch * .*

Want to know how much disk space has been used?

du -h .

Bash shell shortcuts

I have been irritated not having standard keyboard shortcuts, like Ctrl-arrow left (move word left) and Ctrl-arrow right (move word right), available on the bash command line. It turns out they are. If you know what the meta key is. Meta key? Yes, I didn’t know which key this was either.

It turns out that it is the Alt key. This is because historically, many Unix workstations had a key labeled Meta where PCs have a key labeled Alt.

So here is a little bash command line cheat sheet.

  • Ctrl-a: Move to the start of the current line.
  • Ctrl-e: Move to the end of the line.
  • Ctrl-f: Move forward a character.
  • Ctrl-b: Move back a character.
  • Meta-f: Move forward to the end of the next word. Words are composed of letters and digits.
  • Meta-b: Move backward to the start of the next word. Words are composed of letters and digits.

Have fun.

Plugin Manager removed from Notepad++

I needed the compare plugin today. You used to be able to select the Plugin Manager under Plugins -> Plugin Manager. But it was gone 😦 It turns out it has been removed from the standard installation and has to be installed separately. I haven’t been able to find out why. Here quick instructions how to install Plugin Manager.

  • Download the latest version of Plugin Manger from GitHub. Make sure you download the correct version 32 or 64 bit depending on the version of your operating system.
  • Unzip the file.
  • Copy the two directories to the Notepad++ directory. In my case C:\Program Files (x86)\Notepad++.
  • Restart Notepad++.

Plugin Manager is available again under Plugins -> Plugin Manager. Yeah!

Finding out which files are open and by which programs

Grrrrrrr ran into my inotify problem again. So I was wondering how I can see which program has files opened and how many. Well as with everything under Linux it is possible with a few “simple” commands. Try the following command for fun and entertainment.

$ lsof | awk ‘{print $1}’ | sort | uniq -c | sort -g -k 1 | tail

  • lsof: lists the open files
  • awk: takes the first column of the output
  • sort: yep it sorts the output
  • uniq: counts all the same value
  • sort: do you want me to repeat it? a little clarification is necessary -k tells which column to sort on and -g makes sure that the contents is treated like a number
  • tail: gives the last ten entries