运行centos容器

  1. 安装centos:
  2. sudo docker pull centos
  3. 开启容器:
  4. -p端口映射
  5. -d后台运行
  6. -v目录映射 本地数据:容器数据
  7. docker run -p 80:80 -p 8888:8888 -i -d -v /opt/centos:/centos -t centos /bin/bash
  8. 进入:
  9. docker exec -it containerId bash
  10. 停止:
  11. docker stop containerId // containerId 是容器的ID

使用docker环境搭建lamp环境

lamp和资源文件全部映射到物理机 lamp环境使用bitnami-lampstack-7.1.19-1-linux-x64-installer.run 安装lamp选择安装到/centos/lampstack-7.1.19-1

  1. docker run -p 80:80 -p 3306:3306 -i -d -v /home/lxx/centos:/centos -t centos /bin/bash 1

进入

  1. docker exec -it CID bash 1

进入/centos/lampstack-7.1.19-1(即物理机/home/lxx/centos) mysql默认端口3306

  1. ./ctlscript.sh ?
  2. usage: ./ctlscript.sh help
  3. ./ctlscript.sh (start|stop|restart|status)
  4. ./ctlscript.sh (start|stop|restart|status) mysql
  5. ./ctlscript.sh (start|stop|restart|status) apache
  6. help - this screen
  7. start - start the service(s)
  8. stop - stop the service(s)
  9. restart - restart or start the service(s)
  10. status - show the status of the service(s)• 1

进入phpmyadmin

  1. phpmyadmin.example.com 1

如果docker启动失败提示:

  1. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/vhs/mysql-8.0.11-0/mysql/tmp/mysql.sock' (2)• 1

解决方案(不一定有效)

  1. #文件/vhs/mysql-8.0.11-0/mysql/tmp/mysql.sock.lock被锁住了,改为/vhs/mysql-8.0.11-0/mysql/tmp/mysql.sock
  2. mv /vhs/mysql-8.0.11-0/mysql/tmp/mysql.sock.lock /vhs/mysql-8.0.11-0/mysql/tmp/mysql.sock
  3. #启动
  4. /vhs/mysql-8.0.11-0/mysql/bin/mysqld --user=root
  5. /vhs/mysql-8.0.11-0/ctlscript.sh start mysql