I'm using Docker for my Gitlab CI, but need to connect to a remote MySQL server with SSH and then map port 3306 to 127.0.0.1
I use the following command to do the SSH port forward ssh -L 3306:127.0.0.1:3306 user@remoteserver
I've tried viewing the SSH keys in Docker, but can't seem to "ls" into the root/.ssh folder where I believe they're stored, but nothing seems to happen as I get this error: The command '/bin/sh -c cd root/.ssh' returned a non-zero code: 1
I have a public key that i'd like to use from the computer Docker runs on. Where do I copy the contents of this file to?
Any help with this would be great, I am currently testing this out using a dockerfile instead of triggering new pipelines on Gitlab if that makes any difference.
You can map your port with docker run command like that:
docker run -itd --name mysql -p 3306:3306 mysql
Then when your container is running do docker cp /path/to/your/public_key /path/where/you/want/to/drop/your_key
and after that you can do a docker exec -it mysql bash
and add your public key to your authorized key.
You should try some tutorials before trying to docker advanced things with Docker...
In order to connect to a remote server, you need to:
You can therefore:
authorized_keys
on the remoteI have already answered here, to a quite similar question: https://stackoverflow.com/a/42001323/5972308 , I think that corresponds to your need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.