map port
-d background execution
-p map port
--privileged can use systemctl
# docker run --privileged -d -p 9000:80 jiqing9006/centos:httpd /sbin/init
e2e33ac1fb2acdef86c995c79eb746fb552417b112210bc5353de74a2f63e4e7
access container
root@ThinkPad:/home/jiqing# docker ps -q
e2e33ac1fb2a
root@ThinkPad:/home/jiqing# docker exec -it e2e33ac1fb2a /bin/bash
Enable httpd service
systemctl restart httpd
External access to httpd
$ sudo netstat -anpl|grep :9000
tcp6 0 0 :::9000 :::* LISTEN 10352/docker-proxy
Modify the container password. The default root password is random and needs to be modified.
[root@e2e33ac1fb2a /]# 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.
After configuring the password, map out port 22, and you can access it remotely.
install sshd
[root@e2e33ac1fb2a /]# yum install openssh-server
Loaded plugins: fastestmirror, ovl
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.zju.edu.cn
* updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:7.4p1-13.el7_4 will be installed
--> Processing Dependency: openssh = 7.4p1-13.el7_4 for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Processing Dependency: fipscheck-lib(x86-64) >= 1.3.0 for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Processing Dependency: libwrap.so.0()(64bit) for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Processing Dependency: libfipscheck.so.1()(64bit) for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Running transaction check
---> Package fipscheck-lib.x86_64 0:1.4.1-6.el7 will be installed
--> Processing Dependency: /usr/bin/fipscheck for package: fipscheck-lib-1.4.1-6.el7.x86_64
---> Package openssh.x86_64 0:7.4p1-13.el7_4 will be installed
---> Package tcp_wrappers-libs.x86_64 0:7.6-77.el7 will be installed
--> Running transaction check
---> Package fipscheck.x86_64 0:1.4.1-6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
openssh-server x86_64 7.4p1-13.el7_4 updates 458 k
Installing for dependencies:
fipscheck x86_64 1.4.1-6.el7 base 21 k
fipscheck-lib x86_64 1.4.1-6.el7 base 11 k
openssh x86_64 7.4p1-13.el7_4 updates 509 k
tcp_wrappers-libs x86_64 7.6-77.el7 base 66 k
Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 1.0 M
Installed size: 3.0 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): fipscheck-1.4.1-6.el7.x86_64.rpm | 21 kB 00:00
(2/5): openssh-7.4p1-13.el7_4.x86_64.rpm | 509 kB 00:00
(3/5): fipscheck-lib-1.4.1-6.el7.x86_64.rpm | 11 kB 00:00
(4/5): openssh-server-7.4p1-13.el7_4.x86_64.rpm | 458 kB 00:00
(5/5): tcp_wrappers-libs-7.6-77.el7.x86_64.rpm | 66 kB 00:00
--------------------------------------------------------------------------------
Total 1.2 MB/s | 1.0 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : fipscheck-lib-1.4.1-6.el7.x86_64 1/5
Installing : fipscheck-1.4.1-6.el7.x86_64 2/5
Installing : openssh-7.4p1-13.el7_4.x86_64 3/5
Installing : tcp_wrappers-libs-7.6-77.el7.x86_64 4/5
Installing : openssh-server-7.4p1-13.el7_4.x86_64 5/5
Verifying : openssh-7.4p1-13.el7_4.x86_64 1/5
Verifying : openssh-server-7.4p1-13.el7_4.x86_64 2/5
Verifying : fipscheck-1.4.1-6.el7.x86_64 3/5
Verifying : fipscheck-lib-1.4.1-6.el7.x86_64 4/5
Verifying : tcp_wrappers-libs-7.6-77.el7.x86_64 5/5
Installed:
openssh-server.x86_64 0:7.4p1-13.el7_4
Dependency Installed:
fipscheck.x86_64 0:1.4.1-6.el7 fipscheck-lib.x86_64 0:1.4.1-6.el7
openssh.x86_64 0:7.4p1-13.el7_4 tcp_wrappers-libs.x86_64 0:7.6-77.el7
Complete!
start sshd
[root@e2e33ac1fb2a /]# systemctl restart sshd
external ssh access
root@ThinkPad:/home/jiqing# ssh [email protected]
[email protected]'s password:
Last login: Sun May 6 16:55:21 2018 from gateway
[root@e2e33ac1fb2a ~]#