安装docker

参考arch wiki和docker的weiki:

安装和卸载:
        $ sudo pacman -S docker
        Arch 启动Docker
        Arch 下面是使用systemd来管理服务的,可以用systemctl命令来启动docker服务。
        $ sudo systemctl start docker
        如果想设置docker在arch下面开机自动启动,可以用下面的命令:
        $ sudo systemctl enable docker
        Arch下面删除Docker
        删除Docker包。
        $ sudo pacman -R docker
        删除Docker包,同时删除其依赖的包。
        重启docker
        systemctl restart docker
        删除Docker运行过程中产生的镜像、容器等文件。用户生成的配置文件需要手工删除。
        $ rm -rf /var/lib/docker

china

Docker 官方中国区
https://registry.docker-cn.com

网易
http://hub-mirror.c.163.com

ustc
https://docker.mirrors.ustc.edu.cn

$ docker --registry-mirror=https://registry.docker-cn.com daemon

OR

nano /etc/docker/daemon.json
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}
#修改保存后重启 Docker 以使配置生效
systemctl restart docker

运行centos容器

安装centos:
        sudo docker pull centos
        开启容器:
        -p端口映射
        -d后台运行
        -v目录映射 本地数据:容器数据
        docker run -p 80:80 -p 8888:8888 -i -d -v /opt/centos:/centos -t centos /bin/bash
        进入:
        docker exec -it containerId bash
        停止:
        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

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

进入

docker exec -it CID bash

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

./ctlscript.sh ?
usage: ./ctlscript.sh help
       ./ctlscript.sh (start|stop|restart|status)
       ./ctlscript.sh (start|stop|restart|status) mysql
       ./ctlscript.sh (start|stop|restart|status) apache

help       - this screen
start      - start the service(s)
stop       - stop  the service(s)
restart    - restart or start the service(s)
status     - show the status of the service(s)

进入phpmyadmin

phpmyadmin.example.com

如果docker启动失败提示:

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

解决方案(不一定有效)

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

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐