Introduction
I recently had to debug a timezone issue with centos:7 containers.
However, rebuilding the full docker container was slowing me down. It was much quicker to isolate the issue down to the specific container version and the commands required to reproduce the issue.
Setup Dockerfile
Create a file called Dockerfile
in your current directory, for example:
FROM centos:7
RUN yum update -y
Test Dockerfile
Then with the same directory simply run this command:
docker run --rm -it $(docker build -q .)
This one line command will:
- Build the container quietly with
docker build -q .
- Pass the new image ID through to the
docker run
command - Launch an interactive console with
-it
- Then remove the container once you exit the console with
--rm
Example output
If you ran the container above you will see something like this:
% docker run --rm -it $(docker build -q .)
bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8): No such file or directory
[root@bf4436986335 /]#
So in my case I could quickly isolate the timezone issues being caused by the update, and then debug further with an interactive console.
Summary
That’s it! I wrote this entire blog post just so I have a quick way to find that one-liner for debugging docker builds quicker.