1. 程式人生 > >docker中安裝centos

docker中安裝centos

文章目錄

常用命令

如果對命令瞭解不多,建議看下:https://blog.csdn.net/GY325416/article/details/84325522

修改docker映象地址

鑑於國內網路問題,避免拉取映象緩慢,配置國內映象庫可以解決
/etc/docker/daemon.json 檔案可以配置 Daemon,在檔案中加入

#這是網易映象庫
{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
#或者 中國科大映象庫
{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}

重啟docker使其生效

拉取centos映象

centos7會有一些問題,為了避免,使用cnetos6
docker pull centos:6

建立centos容器

#後面的/bin/bash需要加,要不只會建立容器,不會執行centos
#埠對映自己需要的
docker run --name mycentos -p 8888:8080 -p 2222:22 -it centos:6 /bin/bash
#執行後就進入了容器模式

進入之後

修改密碼

預設使用的root使用者,但是還沒有密碼,使用passwd修改密碼

yum映象庫

然後肯定會用到yum下載檔案的,這裡也是國外的倉庫,要配置一下

#下載映象檔案
curl http://mirrors.aliyun.com/repo/Centos-6.repo > /etc/yum.repos.d/CentOS-Base-6-aliyun.repo
#備份原始映象檔案
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
yum makecache #生成一下快取

下載jdk

#為了避免麻煩,我使用openjdk
#執行一下命令後不需要再配置環境
yum install -y java-1.8.0-openjdk

下載啟動訪問tomcat

#下載
curl -O http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz
#解壓
tar zxf apache-tomcat-8.5.35.tar.gz
#啟動(執行tomcat的start指令碼)
apache-tomcat-8.5.35/bin/startup.sh
#檢視端口占用
netstat -an|grep 8080

這個時候訪問宿主機的8888埠就可以看到tomcat首頁了!

注意

當從docker裡面的centos想退出到宿主機命令列時
使用 Ctrl + Q + P,不要使用exit,這樣會停止centos