After docker mirror set up a lot of time but not the native operating direct link docke, it is necessary to ssh service.
The following operation is based on ubuntu.
1. The mirror and pulling into the container
docker pull ubuntu:16.04 docker run -it ubuntu /bin/bash
2. Check whether there is ssh service
Tip no sshd service sshd #
APT- GET Update # first pulled into the container needs to update, because the source is off by default APT -get install OpenSSH-Server Installation # ssh service
If you download too slow can configure the software source image.
sshd # execute ssh command again
Tip: sshd re-exec requires execution with an absolute path
Normal start ssh service, you need a directory / var / run / sshd
mkdir -p /var/run/sshd /usr/sbin/sshd -D &
Ssh port 22 to detect whether the monitored
-tunlp netstat
# prompt bash: netstat: the Command not found
# installation: apt-get install net-tools
3. Modify ssh login restrictions, cancel pam restrictions:
Notes: session required pam_loginuid.so
sed -ri 's/session required pam_loginuid.so/#session required pam_loginuid.so/g' /etc/pam.d/sshd
4. Create public:
ssh-keygen -t rsa
Copy the public key information to the local.
5. Create a script at startup.
vim /run.sh
chmod +x run.sh
Run.sh content inside is:
#!/bin/bash /usr/sbin/sshd -D
After saving execution: exit
Create a new image:
docker commit 9145 sshd/ubuntu ubuntu
Open ports to external access
docker run -p 100081:22 -d sshd/ubuntu /run.sh
Whether detection succeeds:
docker ps
If not, view the log:
docker logs -f container_id (id container)