- You must have BuildKit enabled in Docker.
- You must have
~/.ssh/config
set up with a proper alias for the server you want to access via SSH. - When referencing external resources via SSH, always use a proper domain name, never an SSH alias. In other words, use something like
[email protected]:foo/bar
. - Use the latest
Dockerfile
syntax using# syntax=docker/dockerfile:1.x
at the top.
Last active
February 19, 2023 16:09
-
-
Save Revolucent/d0bb7565aba546e9d58e560027eecd17 to your computer and use it in GitHub Desktop.
Using SSH inside a Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval `ssh-agent` | |
ssh-add | |
docker build -t my:latest --ssh default=$HOME/.ssh/github-private-key . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax=docker/dockerfile:1.5 | |
FROM haskell:8.10.7 | |
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts | |
WORKDIR /tmp/app | |
COPY . . | |
RUN mkdir -p /home/app | |
RUN --mount=type=ssh stack install --local-bin-path /home/app | |
RUN rm -rf /tmp/app | |
WORKDIR /home/app | |
CMD ["./my-exe"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment