In my previous post I wrote a basic Dockerfile to automate the build of my Docker image. The build failed, so now I need to fix it and get my first container up and running.
The build error message was:
The key part here is Couldn't resolve host name. This means that Docker can’t access the internet through the corporate firewall. This is the same problem I had before, and can be solved again by setting up the proxy server details. But I found quite a neat way of testing this, and other, fixes to Dockerfiles.
Interactive Docker container
I can edit my Dockerfile and comment out everything after the first failing statement (dotnet restore), then run the docker container interactively by passing -it as a parameter to docker run. This gives an interactive shell within the container and allows for testing / debugging of Dockerfile commands. Very powerful!
Within the shell I can add my export HTTP_PROXY= settings, run dotnet restore and verify that it all works.
Proxy settings in Dockerfile
A quick bit of googling shows I can pass these environment variables via the Dockerfile:
It’s not ideal to have my username and password hardcoded in a Dockerfile, obviously! But at least this gets me unblocked for my first app. I’ll need to contact the company InfoSec guys to work out what ‘proper’ production usage should be.
My Dockerfile now:
And it builds! In the next post, I’ll try and get it running.