当前位置:   article > 正文

docker容器安装CentOS7.9_docker pull centos7.9

docker pull centos7.9

2.1进入docker镜像官网查看centos版本

容器镜像地址: hub.docker.com

2.2拉取centos7.9的镜像

  1. [root@zzp ~]# docker pull centos:centos7.9.2009
  2. centos7.9.2009: Pulling from library/centos
  3. 2d473b07cdd5: Already exists
  4. Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
  5. Status: Downloaded newer image for centos:centos7.9.2009
  6. docker.io/library/centos:centos7.9.2009
  7. [root@zzp ~]# docker images
  8. REPOSITORY TAG IMAGE ID CREATED SIZE
  9. mysql 5.7 aa803eda0f25 2 weeks ago 433MB
  10. centos centos7.9.2009 eeb6ee3f44bd 13 months ago 204MB

2.3启动容器

备注:

  1. -it 选项是交互形式运⾏
  2. -d表⽰在后台运⾏
  3. CTRL+P+Q 退出容器,但不会把容器停⽌
  4. exit 这种⽅法会连带容器也停⽌掉

2.3.1使⽤镜像id直接启动

  1. [root@zzp ~]# docker run -itd eeb6ee3f44bd /bin/bash
  2. 1742372de4d6959baae854bc9aec68040845592a9396522dbec9c89730e17f19
  3. [root@zzp ~]# docker ps
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. 1742372de4d6 eeb6ee3f44bd "/bin/bash" 21 seconds ago Up 16 seconds sharp_gagarin

2.3.2使⽤镜像id启动并设置容器端口映射和登录name

备注:

-p 5000:22 容器端口为5000,5000映射到22

-- privileged=true 表⽰使⽤特权模式,使⽤这个参数的时候,容器内的root有⽤真正的root权限

  1. [root@zzp ~]# docker rm -f 1742372de4d6
  2. [root@zzp ~]# docker ps
  3. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  4. [root@zzp ~]# docker run -itd --name=centos --privileged=true -p 5000:22 centos:centos7.9.2009 /usr/sbin/init
  5. [root@zzp ~]# docker ps
  6. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  7. 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
  8. [root@zzp ~]#

2.4登入容器

  1. [root@zzp ~]# docker exec -it centos /bin/bash
  2. [root@5c796fd824de /]# ls
  3. anaconda-post.log dev home lib64 mnt proc run srv tmp var
  4. bin etc lib media opt root sbin sys usr
  5. [root@5c796fd824de /]#

2.5安装常用工具及ssh服务

  1. [root@5c796fd824de /]# yum install -y openssh-server vim lrzsz wget gcc-c++
  2. Complete!

2.6安装ifconfig命令

  1. [root@5c796fd824de /]# yum install -y net-tools
  2. Complete!

2.7启动ssh

若不能用systemctl启动则需安装 initscripts

  1. [root@5c796fd824de /]# systemctl start sshd
  2. [root@5c796fd824de /]# netstat -antup | grep sshd
  3. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 247/sshd
  4. tcp6 0 0 :::22 :::* LISTEN 247/sshd
  5. [root@5c796fd824de /]#

2.8设置账号密码

  1. [root@5c796fd824de /]# whoami
  2. root
  3. [root@5c796fd824de /]# echo 12345678|passwd --stdin root
  4. Changing password for user root.
  5. passwd: all authentication tokens updated successfully.

2.9Xshell远程连接docke_centos7.9

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/167324
推荐阅读
相关标签
  

闽ICP备14008679号