1. 程式人生 > >docker上安裝centos映象

docker上安裝centos映象

1、查詢映象源 $ docker search centos NAME DESCRIPTION STARS OFFICIAL centos The official build of CentOS. 3857 [OK] 2、下載映象 docker pull centos 3、檢視已下載的映象 $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 3fa822599e10 6 days ago 204MB 4、啟動映象 $ docker run -itd centos /bin/bash bce6d9a692b26fdf5f7642303c26ffdcaf26917cbfde703dea5c152c320f375d $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS bce6d9a692b2 centos "/bin/bash" About a minute ago Up About a minute 5、進入centos容器
$ docker attach bce6d9a692b2 [[email protected] /]# [[email protected] /]# 6、centos預設沒有ifconfig命令,配置ifconfig [[email protected] /]# ifconfig bash: ifconfig: command not found [[email protected] /]# [[email protected] /]# yum search ifconfig Loaded plugins: fastestmirror, ovl base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): extras/7/x86_64/primary_db | 130 kB 00:00:01 (2/4): base/7/x86_64/group_gz | 156 kB 00:00:01 (3/4): updates/7/x86_64/primary_db | 3.8 MB 00:00:17 (4/4): base/7/x86_64/primary_db | 5.7 MB 00:00:21 Determining fastest mirrors * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: mirrors.aliyun.com ==================================================== Matched: ifconfig ================================================== net-tools.x86_64 : Basic networking tools [
[email protected]
/]# [[email protected] /]# [[email protected] /]# yum install net-tools.x86_64 [[email protected] /]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0 ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet) RX packets 7560 bytes 11081500 (10.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5595 bytes 305703 (298.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 7、配置ssh
a、修改Centos root密碼 # passwdChanging password for user root.New password: 123456BAD PASSWORD: The password is shorter than 8 charactersRetype new password: 123456passwd: all authentication tokens updated successfully. b、安裝openssh yuminstall openssh-server -y  c、生成公鑰、私鑰 [[email protected] /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_keyGenerating public/private rsa key pair.Enter passphrase (empty for no passphrase): (直接回車)Enter same passphrase again: (直接回車)Your identification has been saved in /etc/ssh/ssh_host_rsa_key.Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.The key fingerprint is:33:3c:34:49:e4:76:7d:45:cc:69:ac:46:85:ab:27:9e [email protected] key's randomart image is:+--[ RSA 2048]----+| .o +=+|| o . . o =o|| * . o = || + o = || S o || + o . || . + || E || |+-----------------+ [[email protected] /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_ecdsa_keyGenerating public/private rsa key pair.Enter passphrase (empty for no passphrase): (直接回車)Enter same passphrase again: (直接回車)Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.The key fingerprint is:09:ac:b0:61:55:de:e8:4f:5e:20:d9:fc:1e:b6:d7:79 [email protected] key's randomart image is:+--[ RSA 2048]----+| ... || . o * || + B = || . + o o + || . . . S = || + + o . . || o o . o E|| . . || |+-----------------+ [[email protected] /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_ed25519_keyGenerating public/private rsa key pair.Enter passphrase (empty for no passphrase): (直接回車)Enter same passphrase again: (直接回車)Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.The key fingerprint is:63:0d:b5:fb:55:a4:56:47:43:6d:68:c0:47:2e:84:24 [email protected] key's randomart image is:+--[ RSA 2048]----+| E.ooooo=*|| o.o..++=|| . . .o+..|| o . o . || S o . || . . . . || . || || |+-----------------+ d、編寫啟動指令碼 # vi /run.sh#!/bin/bash/usr/sbin/sshd -D# chmod +x /run.sh e、退出容器,儲存映象 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS bce6d9a692b2 centos "/bin/bash" About a minute ago Up About a minute #從容器退出,但不停止容器: Ctrl+P+Q [[email protected] ~]# [[email protected] ~]# $ $ docker ps #回到Docker下面,停止容器: docker stop <容器ID> $ docker stop bce6d9a692b2 bce6d9a692b2 #提交當前容器到映象: docker commit <容器ID> <NAME:VERSION> $ docker commit bce6d9a692b2 centos_me:v1.0 $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE centos_me v1.0 4569dd302889 38 minutes ago 366MB f、重新啟動容器 $ docker run --net=host --name hdoop0 -d -p 5001:22 centos_me:v1.0 /run.sh 備註:1、“-p 5001:22” 是將容器的ssh埠22對映都宿主主機的5001埠上 2、‘--name hdoop0’重新命名容器名 或者:docker run --name hadoop2 -d -p 5002:22 centos_me:v1.0 /usr/sbin/sshd -D g、遠端連線測試