CentOS安裝Docker

安裝docker

1. 安裝docker服務
yum install docker
2. 啓動Docker服務
service docker start
chkconfig docker on

systemctl start docker.service
systemctl enable docker.service
3. 下載官方的CentOS鏡像到本地
docker pull centos
確認鏡像已經被獲取:docker images centos
4. 運行一個docker容器
docker run -i -t centos /bin/bash
5. 安裝SSHD
yum install openssh-server
whereis sshd
/usr/sbin/sshd -D
centos下啓動sshd的時候出現如下錯誤:
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
依次執行下列命令:
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key #直接回車
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key #直接回車
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ”
然後再啓動sshd服務,若沒有錯誤提示則表示啓動成功
修改sshd_config,將UsePAM=yes改爲UsePAM=no
6. 安裝passwd並設置root密碼
yum -y install passwd
passwd root
7. 修改密碼後執行exit並將修改的容器內容提交到鏡像
docker ps -l #查看docker容器的id
docker commit containerid imagename
8. 通過docker run啓動一個新的容器
docker run -d -p 10086:22 -p 9090:9090 imagename /usr/sbin/sshd -D
注:-d表示後臺運行, -p表示端口映射
9. ssh root@localhost -p 10086登錄後安裝所需的軟件
10. 停止docker容器
docker stop containerid
11. 停止docker服務
service docker start|stop|restart

常見問題

1. ifconfig無效
yum -y install net-tools

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章