Home > OS >  Docker create Centos container
Docker create Centos container

Time:11-24

1, pull the Centos image
Docker pull centos: centos8
2, create a container
Docker run - itd - p 5000:22 - name CentosY & lt; ImageID>/bin/bash
So you can start a Centos stays in the background, if less/bin/bash, Docker will born into a Container but soon stopped, not always running even with the -d parameter
-i: interactive operation
- t: terminal
Background - d
(the host port: -p container port mapping container port)

3, into the container
Docker ps # to check the container ID
Docker attach & lt; The CONTAINER ID & gt;
4, after entering CentosY, no ifconfig and SSH
Yum install.net - tools. X86_64
The RPM - qa | grep SSHD
The RPM - qa | grep SSH
Netstat TNLP | grep SSH
Yum install - y openssh - server
5, the SSH

Execute the following command:
SSH - the keygen -t rsa - f/etc/SSH/ssh_host_rsa_key
SSH - the keygen -t rsa - f/etc/SSH/ssh_host_ecdsa_key
SSH - the keygen -t rsa - f/etc/SSH/ssh_host_ed25519_key
Restart the
The/usr/sbin/SSHD - D & amp;
Check to see if the SSH start-up success
Netstat LNTP | grep SSHD

6, change the root password
Yum install passwd
Passwd root

7, Ctrl + P + Q # exit but don't stop the container
8, docker stop & lt; Container ID> # stop container
9, docker commit & lt; Container ID> # to commit the current container to mirror
10 and docker run - itd - p 5000:22 & lt; Just submit mirror ID>/bin/bash # start new container, and port mapping

Then you can directly SSH connection new container,
  • Related