免責事項:この記事はブロガーオリジナル記事ですが、許可ブロガーなく再生してはなりません。https://blog.csdn.net/tladagio/article/details/91509807
ホスト:CentOSに7
IP:192.168.14.57
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
まず、ドッキングウィンドウをインストール
[root@localhost ~]# yum install -y docker
第二に、ミラー
図1に示すように、容器は、画像のCentOSを取得します
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8ba884070f61: Pull complete
Digest: sha256:b5e66c4651870a1ad435cd75922fe2cb943c9e973a9673822d1414824a1d0475
Status: Downloaded newer image for centos:latest
視鏡画像をドッカー2、
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 9f38484d220f 2 months ago 202MB
第三に、コンテナ
1、ドッキングウィンドウコンテナを起動
[root@localhost ~]# docker run -tdi --privileged centos init
38b8c5a053df39ef0a92c53cc3b038484c820c998b6e8b9a9ed88a7ddd3b370c
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
38b8c5a053df centos "init" 15 seconds ago Up 11 seconds naughty_euclid
[root@localhost ~]# docker exec -it naughty_euclid /bin/bash
-i:標準入力をオープンに保ち、デフォルトはfalseです
-t:ダミー端子を割り当てるかどうかを、デフォルトはfalseです
注意:あなたが--privileged追加しない場合、sshdサービスを、次のことは正常に起動することはできません
[root@38b8c5a053df /]# systemctl start sshd
Failed to get D-Bus connection: Operation not permitted
2、rootのパスワードを変更します
[root@38b8c5a053df /]# passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
3、インストールOpenSSHは(コンテナは、インターネットにアクセスできることを確認してください)
[root@38b8c5a053df /]# yum install -y openssh-server openssh-clients
4、sshdサービスを開始
[root@38b8c5a053df /]# systemctl start sshd
[root@38b8c5a053df /]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-06-12 07:22:29 UTC; 1s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 2145 (sshd)
CGroup: /docker/38b8c5a053df39ef0a92c53cc3b038484c820c998b6e8b9a9ed88a7ddd3b370c/system.slice/sshd.service
└─2145 /usr/sbin/sshd -D
‣ 2145 /usr/sbin/sshd -D
Jun 12 07:22:29 38b8c5a053df systemd[1]: Starting OpenSSH server daemon...
Jun 12 07:22:29 38b8c5a053df sshd[2145]: Server listening on 0.0.0.0 port 22.
Jun 12 07:22:29 38b8c5a053df sshd[2145]: Server listening on :: port 22.
Jun 12 07:22:29 38b8c5a053df systemd[1]: Started OpenSSH server daemon.
5、ネットのツールをインストールし、使用netstatコマンドは、リスニングポートを表示-ntlp
[root@38b8c5a053df /]# yum install -y net-tools
[root@38b8c5a053df /]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2145/sshd
tcp6 0 0 :::22 :::* LISTEN 2145/sshd
6、終了コンテナは、コンテナのIDを覚えている:38b8c5a053dfを
[root@38b8c5a053df /]# exit
第四に、新しい画像として保存
1、コンテナは新しいsshdを保存するためにドッキングウィンドウは、commitコマンドを使用して、変更されたため:CentOSのミラーを
[root@localhost ~]# docker commit -m 'install openss' -a 'Docker Newbee' 38b8c5a053df sshd:centos
2、ポートマッピングに> 22 10022-を追加しながら、新たなコンテナを開始します。10022は、SSHサービスの22個のコンテナのホストポートをリスニングポートです
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sshd centos 3c6c67905ece 3 minutes ago 307MB
centos latest 9f38484d220f 2 months ago 202MB
[root@localhost ~]# docker run -d -p 10022:22 sshd:centos /usr/sbin/sshd -D
48437032376b806b2df976ac6cd5b9457a6b7bd7d5d8013fbc24bb2a2a22c0ca
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
48437032376b sshd:centos "/usr/sbin/sshd -D" 9 seconds ago Up 5 seconds 0.0.0.0:10022->22/tcp keen_mirzakhani
38b8c5a053df centos "init" 16 minutes ago Up 16 minutes naughty_euclid
第五に、リモートログイン
1、リモートホストPCのホストポート10022にログインするSSH
[C:\Users]$ ssh [email protected] 10022
Connecting to 192.168.14.57:10022...
Connection established.
To escape to local shell, press Ctrl+Alt+].
WARNING! The remote SSH server rejected X11 forwarding request.
[root@48437032376b ~]#