docker安装

75次阅读
没有评论

1,https://hub.docker.com/?overlay=onboarding 下载 ,一路 Next,点击 Finish 完成安装。 重启电脑

https://docs.docker.com/desktop/install/windows-install 这个默认有compose

https://github.com/docker/compose/releases 增加安装compose

2 ,执行docker run hello-world 如果遇到docker: error during connect: This error may indicate that the docker daemon is not running

你没有登录桌面的doker设置要登录 或者 在cmd执行 cd “C:Program FilesDockerDocker” DockerCli.exe -SwitchDaemon 这两条命令

3, “registry-mirrors”: [
“https://udopg8mw.mirror.aliyuncs.com”,
“https://registry.docker-cn.com”,
“http://hub-mirror.c.163.com”
] 设置镜像加速

4,安装mysql5.7

运行mysql

docker pull mysql:5.7

docker run –name mysql -d -it -p 3333:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.7

创建容器名称为mysql3308,密码为root
1.启动容器
docker start mysql

docker exec -it mysql bash 进入容器

mysql -uroot –p root 再进入mysql 执行想要的

修改密码

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘123456’

授权添加远程用户登录访问

CREATE USER ‘admin’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;

查找Docker内,MySQL配置文件my.cnf的位置

mysql –help | grep my.cnf

会输出数据文件的存放路径 /var/lib/mysql/

show variables like ‘%datadir%’;

docker inspect mysql 查看状态

powershell运行 复制挂载 配置 数据 logs

首次安装的时候需要复制 docker cp mysql3308:/etc/mysql/conf.d D:1kaifahuanjingdockerwnmpmysqlconf.d

docker run –restart=always –name mysql -d -it -p 3333:3306 -e MYSQL_ROOT_PASSWORD=root -v D:1kaifahuanjingdockerwnmpmysqlconf.d:/etc/mysql/conf.d -v D:1kaifahuanjingdockerwnmpmysqldata:/var/lib/mysql -v D:1kaifahuanjingdockerwnmpmysqllogs:/var/log/mysql mysql:5.7

5,安装 nginx docker pull nginx

复制挂载 docker cp nginx:/etc/nginx/nginx.conf D:1kaifahuanjingdockerwnmpnginxconfnginx.conf

docker cp nginx:/etc/nginx/conf.d D:1kaifahuanjingdockerwnmpnginxconfconf.d
docker cp nginx:/etc/nginx/nginx.conf D:1kaifahuanjingdockerwnmpnginxconfnginx.conf
docker cp nginx:/usr/share/nginx/html D:1kaifahuanjingdockerwnmpnginxhtml
docker cp nginx:/var/log/nginx D:1kaifahuanjingdockerwnmpnginxlogs

docker cp mysql:/etc/mysql/conf.d D:1kaifahuanjingdockerwnmpmysql
docker cp mysql:/var/lib/mysql D:1kaifahuanjingdockerwnmpmysqldata
docker cp mysql:/var/log/mysql D:1kaifahuanjingdockerwnmpmysqllogs

docker cp php:/var/www/html D:1kaifahuanjingdockerwnmpnginx
docker cp php:/usr/local/etc D:1kaifahuanjingdockerwnmpphp

docker cp D:下载phpredis-5.3.6.tar.gz php-fpm:/tmp

docker run –restart=always –name nginx -d -it -p 9090:80 -v D:1kaifahuanjingdockerwnmpnginxconfnginx.conf:/etc/nginx/nginx.conf -v
D:1kaifahuanjingdockerwnmpnginxconfconf.d:/etc/nginx/conf.d -v
D:1kaifahuanjingdockerwnmpnginxlogs:/var/log/nginx -v D:1kaifahuanjingdockerwnmpnginxhtml:/usr/share/nginx/html -d nginx

5,安装php
docker pull php:7.4-fpm

docker run –name myphp -v D:1kaifahuanjingdockerwnmpnginxhtml:/www -d php:7.4-fpm

docker run –name runoob-php-nginx -p 9090:80 -d -v D:1kaifahuanjingdockerwnmpnginxhtml:/usr/share/nginx/html -v D:1kaifahuanjingdockerwnmpnginxconfnginx.conf:/etc/nginx/nginx.conf –link myphp:php nginx
安装mysqli拓展
docker exec -it php /bin/bash
cd /usr/local/bin docker-php-ext-install mysqli
docker-php-ext-install mysqli pdo pdo_mysql

安装 redis拓展
docker exec -it php-fpm bash

curl -L -o /tmp/redis.tar.gz https://codeload.github.com/phpredis/phpredis/tar.gz/5.3.6

下载不了的话可以手动cp 进去容器再解压

cd /tmp

tar -zxvf redis.tar.gz

mv phpredis-5.3.6 /usr/src/php/ext/

cd /usr/local/bin

docker-php-ext-install phpredis-5.3.6

2、安装composer
php -r “copy(‘https://install.phpcomposer.com/installer’, ‘composer-setup.php’);”
php composer-setup.php
php -r “unlink(‘composer-setup.php’);”
mv composer.phar /usr/local/bin/composer

Docker为PHP安装gd扩展
//进入PHP容器
//更新软件源
apt update
//安装各种库
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
//解压源码
docker-php-source extract
//进入gd源码文件夹
cd /usr/src/php/ext/gd
//准备编译
docker-php-ext-configure gd –with-webp-dir=/usr/include/webp –with-jpeg-dir=/usr/include –with-png-dir=/usr/include –with-freetype-dir=/usr/include/freetype2
//编译安装
docker-php-ext-install gd
//查看是否成功安装gd扩展
php -m | grep gd
//重启容器

先安装zip需要的依赖

apt-get install -y zlib1g-dev && apt-get install -y libzip-dev

安装并启动zip扩展

docker-php-ext-install zip

安装PHP-bcmath扩展
docker-php-ext-install bcmath

到这里compsoer update 已经可以正常使用了。

如果想在容器外部使用

2、docker exec -it cb6c1fe83bff(php容器ID) bash -c ‘cd 项目名 && composer install’

正文完
 
评论(没有评论)