赞
踩
容器镜像地址: hub.docker.com
- [root@zzp ~]# docker pull centos:centos7.9.2009
- centos7.9.2009: Pulling from library/centos
- 2d473b07cdd5: Already exists
- Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
- Status: Downloaded newer image for centos:centos7.9.2009
- docker.io/library/centos:centos7.9.2009
- [root@zzp ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- mysql 5.7 aa803eda0f25 2 weeks ago 433MB
- centos centos7.9.2009 eeb6ee3f44bd 13 months ago 204MB
备注:
- -it 选项是交互形式运⾏
-
- -d表⽰在后台运⾏
-
- CTRL+P+Q 退出容器,但不会把容器停⽌
-
- exit 这种⽅法会连带容器也停⽌掉
- [root@zzp ~]# docker run -itd eeb6ee3f44bd /bin/bash
- 1742372de4d6959baae854bc9aec68040845592a9396522dbec9c89730e17f19
- [root@zzp ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 1742372de4d6 eeb6ee3f44bd "/bin/bash" 21 seconds ago Up 16 seconds sharp_gagarin
备注:
-p 5000:22 容器端口为5000,5000映射到22
-- privileged=true 表⽰使⽤特权模式,使⽤这个参数的时候,容器内的root有⽤真正的root权限
- [root@zzp ~]# docker rm -f 1742372de4d6
- [root@zzp ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- [root@zzp ~]# docker run -itd --name=centos --privileged=true -p 5000:22 centos:centos7.9.2009 /usr/sbin/init
-
- [root@zzp ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 132d3d3be6c8 centos:centos7.9.2009 "/usr/sbin/init" About a minute ago Up About a minute 0.0.0.0:5000->22/tcp, :::5000->22/tcp keen_yalow
- [root@zzp ~]#
- [root@zzp ~]# docker exec -it centos /bin/bash
- [root@5c796fd824de /]# ls
- anaconda-post.log dev home lib64 mnt proc run srv tmp var
- bin etc lib media opt root sbin sys usr
- [root@5c796fd824de /]#
- [root@5c796fd824de /]# yum install -y openssh-server vim lrzsz wget gcc-c++
-
- Complete!
- [root@5c796fd824de /]# yum install -y net-tools
-
- Complete!
若不能用systemctl启动则需安装 initscripts
- [root@5c796fd824de /]# systemctl start sshd
- [root@5c796fd824de /]# netstat -antup | grep sshd
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 247/sshd
- tcp6 0 0 :::22 :::* LISTEN 247/sshd
- [root@5c796fd824de /]#
- [root@5c796fd824de /]# whoami
- root
- [root@5c796fd824de /]# echo 12345678|passwd --stdin root
- Changing password for user root.
- passwd: all authentication tokens updated successfully.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。