1.删除所有的容器 docker container rm -f `docker ps -a -q`
2.宿主机新建目录 mkdir -p /opt/vol/mysql /opt/vol/html
3.启动容器 docker container run -it –name=”old_centos” -v /opt/vol/mysql:/var/lib/mysql -v /opt/vol/html:/var/www/html centos:7
4.优化yum源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache
5.安装软件 yum install openssh-server httpd mysql mysql-server php php-mysql -y
6. 启动sshd
mkdir /var/run/sshd
echo ‘UseDNS no’ >> /etc/ssh/sshd_config
sed -i -e ‘/pam_loginuid.so/d’ /etc/pam.d/sshd
echo ‘root:123456’ | chpasswd
/usr/bin/ssh-keygen -A

补充:sshd镜像使用
docker commit 620dba4a45d2 centos_ssh
运行 docker run -d -p 2222:22 c7ssh /usr/sbin/sshd -D 

7./etc/init.d/mysqld start
8.启动脚本 cd /opt/vol/html && vim init.sh
#!/bin/bash
/etc/init.d/mysqld start
/etc/init.d/httpd start
/usr/bin/sshd -D

其他的启动脚本
vim /init.sh
service nginx start
service nginx restart
service php-fpm7 start
service php-fpm7 restart
tail -f /etc/hosts
#最后一步是吼住不动了

提交容器
docker commit

启动容器
docker container run -d –name=”old_centos—_1″ -v /opt/vol/mysql:/var/lib/mysql -v /opt/vol/html:/var/www/html -p 2222:22 -p 8888:80 -p 33060:3306 容器名 /var/www/html/init.sh

Comments are closed.

Post Navigation