I use the following Dockerfile
to generate a docker image as a ubuntu toolchain environment for CLion.
As it shows, I don't have any configuration about adding users.
And the following shows that I connect CLion to this docker server:
When I click the red circled settings, it shows this:
My question is, which username does this "docker for mac" use to log into the docker server?
In this docker, I use root
to create a public ssh key, and then added it to my remote git site. I found that when toolchain runs cmake
, it cannot be pull down the git repo from my remote git site, because of insufficient user permissions. So I guess "docker for mac" does not log into docker images as root user (for whom I've already created a ssh public key)
CodePudding user response:
There is no such a concept of user in "Docker for Mac". It is only a product that encapsulate the necessary elements to successfully run linux based containers on MacOS.
In your use case, you need to make the SSH private key corresponding to the public key pair from your machine to the underlying Ubuntu container in which you need to clone your git repository.
One naive option is create your ~./ssh
folder and related stuff and COPY
the private key, but it is absolutely not recommended because it will make, in fact, your key publicly accesible to anyone with access to the image.
Instead, you may try an alternative approach. Honestly I have never use it, so please, take the necessary care. The idea is extracted from this article and based in the use of BuildKit. Basically, during the build process your host SSH build configuration is make accesible to the underlying container.
As explained in the article, in can be summarized in the following steps:
- Install an SSH client, like
openssh-client
, in your Ubuntu image
RUN apt-get update && \
apt-get install --yes --no-install-recommends \
openssh-client \
...
- Get the necessary public keys scanning your Git server. As an example, if using
github.com
:
RUN mkdir -p -m 0600 ~/.ssh && \
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- Identify the commands that require SSH in your Dockerfile by using
-mount=type=ssh
, for example:
RUN --mount=type=ssh \
git clone git@<host>:<organization>/google-test.git
- Build with Buildkit and flags, which involves providing the environment variable
DOCKER_BUILDKIT=1
and then run your build as follows:
docker build --ssh default .
Probably you will need to configure the env variable in CLion (perhaps in Add environment?).
The process is as well documented in the official Docker documentation.