docker容器安装CentOS7.9

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

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

docker容器安装CentOS7.9_第1张图片

docker容器安装CentOS7.9_第2张图片

2.2拉取centos7.9的镜像

[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

2.3启动容器

备注:

-it 选项是交互形式运⾏

-d表⽰在后台运⾏

CTRL+P+Q 退出容器,但不会把容器停⽌

exit 这种⽅法会连带容器也停⽌掉

2.3.1使⽤镜像id直接启动

[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

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

备注:

-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 ~]# 

2.4登入容器

[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 /]# 

2.5安装常用工具及ssh服务

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

Complete!

2.6安装ifconfig命令

[root@5c796fd824de /]# yum install -y net-tools

Complete!

2.7启动ssh

若不能用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 /]# 

2.8设置账号密码

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

2.9Xshell远程连接docke_centos7.9

docker容器安装CentOS7.9_第3张图片

你可能感兴趣的:(Linux服务器运维小知识点,docker,运维,容器)