作者:兄弟465748208_279 | 来源:互联网 | 2023-10-09 20:29
安装docker:用yum源安装-查看是否已安装docker列表:yumlistinstalled|grepdocker安装docker:yum-yinstalldocker启动d
安装docker:
用yum源安装-查看是否已安装docker列表:
yum list installed | grep docker
安装docker:
启动docker
查看docker服务状态
自此docker安装完成;
进入docker后修改时区:
#修改时区,设置为上海时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
为docker设置国内阿里云的镜像加速器:
vi /etc/docker/daemon.json
添加内容如下:
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
配置文件daemmon,json添加阿里云镜像地址,保存并退出,重启docker服务:
systemctl restart docker
sudo systemctl status docker
sudo docker ps -a -q // 查看所有容器ID
sudo docker stop $(sudo docker ps -a -q) // stop停止所有容器
sudo docker rm $(sudo docker ps -a -q) // remove删除所有容器
一次性停止删除容器:
docker stop $(docker ps -q) & docker rm $(docker ps -aq)
docker重启之后,就可以正常拉取镜像了:
根据Hyperf官方文档安装:
# 下载并运行 hyperf/hyperf 镜像,并将镜像内的项目目录绑定到宿主机的/mnt/hgfs/www(虚拟机共享目录)
docker run -v /mnt/hgfs/www/hyperf/:/hyperf-skeleton -p 9501:9501 -it --entrypoint /bin/sh hyperf/hyperf:7.4-alpine-v3.9-cli
# 镜像容器运行后,在容器内安装 Composer
wget https://github.com/composer/composer/releases/download/1.8.6/composer.phar
或
curl -sS https:
chmod u+x composer.phar
mv composer.phar /usr/local/bin/composer
# 将 Composer 镜像设置为阿里云镜像,加速国内下载速度
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer
# 通过 Composer 安装 hyperf/hyperf-skeleton 项目
composer create-project hyperf/hyperf-skeleton
# 进入安装好的 Hyperf 项目目录
cd hyperf-skeleton
# 启动 Hyperf
php bin/hyperf.php start
接下来,就可以在 /mnt/hgfs/www/ 中看到您安装好的代码了。由于 Hyperf 是持久化的 CLI 框架,当您修改完您的代码后,通过 CTRL + C
终止当前启动的进程实例,并重新执行php bin/hyperf.php start启动命令即可。
热更新/热重载
-
ha-ni-cc/hyperf-watch 一个基于 Swoole 实现的通用热更新组件
git地址下载:https://github.com/ha-ni-cc/hyperf-watch.git
将'watch'文件放在项目更目录下,在容器中执行:
启动监听:
启动监听并删除代理类缓存(./runtime/container):
退出监听:
安装 Wsdebug
git地址 :https://github.com/lamplife/wsdebug
注意运行docker时同步多个端口:
docker run -v /mnt/hgfs/www/hlyes_v1/:/hlyes -p9500:9500 -p 9501:9501 -p 9503:9503 -p 9504:9504 -p 9600:9600 -p 9601:9601 -p 9602:9602 -it --entrypoint /bin/sh hyperf/hyperf:7.2-alpine-v3.9-cli
指定容器ID
docker run -v /mnt/hgfs/www/hlyes_v1:/hlyes -p 9600:9600 -p 9604:9604 -p 9601:9601 -p 9500:9500 -it --entrypoint /bin/sh 9e7b52913c1a
进入已启动的容器
docker exec -it 775c7c9ee1e1 /bin/bash
启动redis
通过docker-compose启动
安装
#curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#chmod +x /usr/local/bin/docker-compose
#docker-compose --version
#docker-compose version
编写docker-compose.yml
version: '2'
services:
org:
build:
context: ./dev_hyperf
networks:
- dev_hyperf
volumes:
- /mnt/hgfs/www/hlyes_v1/hlyes_v1_org:/www
ports:
- "9601:9601"
api:
build:
context: ./dev_hyperf
ports:
- "9500:9500"
networks:
- dev_hyperf
volumes:
- /mnt/hgfs/www/hlyes_v1/hlyes_v1_api:/www
center:
build:
context: ./dev_hyperf
ports:
- "9501:9501"
- "9604:9604"
networks:
- dev_hyperf
volumes:
- /mnt/hgfs/www/hlyes_v1/hlyes_v1_center:/www
cache_server:
image: "redis:6.0.4"
networks:
- dev_hyperf
networks:
dev_hyperf:
编写Dockerfile
docker_composer/dev_hyperf/Dockerfile
FROM hyperf/hyperf:7.4-alpine-v3.9-cli
WORKDIR /www
# CMD ["php","bin/hyperf.php","start"]
CMD php watch
Dockerfile执行sh
FROM hyperf/hyperf:7.4-alpine-v3.9-cli
##
# ---------- env settings ----------
##
# --build-arg timezOne=Asia/Shanghai
ARG timezone
ENV TIMEZOnE=${timezone:-"Asia/Shanghai"} \
APP_ENV=dev
# update
RUN set -ex \
&& apk update \
# show php version and extensions
&& php -v \
&& php -m \
# ---------- some config ----------
&& cd /etc/php7 \
# - config PHP
&& { \
echo "upload_max_filesize=100M"; \
echo "post_max_size=108M"; \
echo "memory_limit=1024M"; \
echo "date.timezOne=${TIMEZONE}"; \
} | tee conf.d/99-overrides.ini \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# ---------- clear works ----------
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
WORKDIR /www
CMD sh /www/entrypoint.sh
entrypoint.sh
#! /bin/bash
php /www/hlyes_v1_center/watch &
php /www/hlyes_v1_crm/watch &
php /www/hlyes_v1_fms/watch &
php /www/hlyes_v1_mms/watch &
php /www/hlyes_v1_oms/watch &
php /www/hlyes_v1_org/watch &
php /www/hlyes_v1_pms/watch &
php /www/hlyes_v1_srm/watch &
php /www/hlyes_v1_api/watch &
php /www/hlyes_v1_tms/watch
删除容器
sudo docker rm $(sudo docker ps -a -q)
启动运行
docker-compose -f /mnt/hgfs/www/docker_compose/dev-compose.yml up
docker-compose -f E:\www\docker_compose\dev-compose.yml up -d --build
服务注册:
consul agent -dev -client 0.0.0.0 -ui
redis 常用命令
redis-server /usr/local/redis/etc/redis.conf //启动redis
pkill redis //停止redis