What is the working directory of a Docker Golang application?
When I serve a Golang Application from within the official Docker Hub Repository I wonder what will be the default working directory the application starts up?
Background: I will have to map local Certificate Authority and server keys into the container to serve TLS https and I wonder where to map them to the application will be able to grab them in current working directory of the application from within the container?
2 Solutions collect form web for “What is the working directory of a Docker Golang application?”
If you are using the golang:1.X-onbuild image from DockerHub will be copied into(https://hub.docker.com/_/golang/)
this means all files and directories from the directory where you run the
command will be copied into the container.
And the workdir of all images is
Go will return the current working directory using
currdir, _ = filepath.Abs(filepath.Dir(os.Args))
Executed within a golang container and right after startup, the pwd is set to
The current working directory of a golang application starting up within a Docker container is thus
/go/src/app. In order to map a file/directory into a container you will habe to use the
-v-switch as described in the Documentation for run:
Will map a local file into the pwd of the dockerized golang app.