Create a config file in C: \ Users \ username \ .ssh and write the following
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile D:/vagrant/centos7/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
$ scp .vagrant/machines/default/virtualbox/private_key default:/home/vagrant/.ssh/
$ vagrant ssh
# private_Change the execute permission of key
$ chmod 600 ~/.ssh/private_key
#Note`vagrant up`Run in the directory
> scp .vagrant/machines/default/virtualbox/private_key vagrant-os:/home/vagrant/.ssh/
#SSH connection to Guest OS
> vagrant ssh
# private_Change the execution authority of key (in Guest OS)
$ chmod 600 ~/.ssh/private_key
FROM ruby:2.5.1
#Update repository and install dependent modules
RUN apt-get update -qq && \
apt-get install -y build-essential \
nodejs
#Create a working directory with the name webapp directly under the root (application directory in the container)
RUN mkdir /webapp
WORKDIR /webapp
#Host Gemfile and Gemfile.Copy lock to container
ADD Gemfile /webapp/Gemfile
ADD Gemfile.lock /webapp/Gemfile.lock
#Run bundle install
RUN bundle install
#Copy everything in the host's application directory to a container
ADD . /webapp
# puma.Create a directory to place sock
RUN mkdir -p tmp/sockets
#From here to the end is the openssh setting
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
# /etc/ssh/sshd_Rewrite config settings
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
#Copy public key
COPY authorized_keys /root/authorized_keys
EXPOSE 22
# Activate authorized_keys & Boot sshd
CMD mkdir ~/.ssh && \
mv ~/authorized_keys ~/.ssh/authorized_keys && \
chmod 0600 ~/.ssh/authorized_keys && \
#Finally start ssh
/usr/sbin/sshd -D
#Copy public key
$ cp ~/.ssh/authorized_keys .
# build
$ docker build ./ -t example
#Launch Docker Container
# Port:10000 Port:Transfer to 22
$ docker run -d -p 10000:22 example
#SSH connection to Docker Container
$ ssh -o 'StrictHostKeyChecking no' [email protected] -p 10000 -i ~/.ssh/private_key
$ ssh -o 'StrictHostKeyChecking no' docker-os
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile D:/vagrant/centos7/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
#Added below
Host docker-os
Hostname 127.0.0.1
User root
Port 10000
ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -W %h:%p default
IdentityFile D:/vagrant/centos7/.vagrant/machines/default/virtualbox/private_key
After launching VScode Remote Development installation from extension Edit from sshTargets in Remote Explorer
Recommended Posts