我的 Docker-compose.yml 是:
version: '3.8'
services:
app:
build:
context: .
dockerfile: ./docker/app/Dockerfile
command: bash -c "
if [ ! -d /var/www/vendor ] ; then composer install --no-interaction ; fi &&
if [ ! -f /var/www/.env ] ; then composer env-set ; fi &&
if [ ! -d /var/www/node_modules ] ; then npm install && npm install chokidar && npm run dev ; fi &&
if [ ! -d /var/www/public/storage ] ; then php /var/www/artisan storage:link ; fi &&
php /var/www/artisan octane:start --no-interaction --host=0.0.0.0 --port=8000 --watch &&
bash /var/www/docker/scheduler/run.sh
"
volumes:
- .:/var/www
- ./docker/app/php-settings.ini:/etc/php/8.3/cli/conf.d/php-settings.ini
- ./docker/app/xdebug.ini:/etc/php/8.3/cli/conf.d/20-xdebug.ini
working_dir: /var/www
depends_on:
- database
ports:
- "9010:9003"
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
nginx:
image: nginx:alpine
ports:
- '${APP_PORT:-80}:80'
volumes:
- .:/var/www
# RoadRunner
- ./docker/nginx/roadrunner.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
restart: unless-stopped
database:
image: postgres:alpine
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: ${DB_DATABASE:-devices}
POSTGRES_USER: ${DB_USERNAME:-root}
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
restart: unless-stopped
influx:
image: influxdb:latest
ports:
- '${INFLUXDB_PORT:-8086}:8086'
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUXDB_USERNAME:-influx}
DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD:-password}
DOCKER_INFLUXDB_INIT_ORG: influx
DOCKER_INFLUXDB_INIT_BUCKET: influx
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_TOKEN:-tsb8f_gfi-dpo86qFaD58MRAIBadSWXLjL2orRMwkciE3Cit7Y_-lbSrqEvqhzU7XZ8ksxqhSWf4-KQs1CTG8A==}
depends_on:
- app
restart: unless-stopped
networks:
- web
volumes:
db_data:
networks:
web:
external: true
当我尝试通过操作系统curl作为
curl --location 'http://localhost:8086/api/v2' --header "Authorization: Token ${INFLUXDB_TOKEN}
进行连接时 - 一切都结束了。
当我尝试在 PHP 中使用相同的方法时:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://localhost:8086/api/v2');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_PORT, 8086);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Authorization: Token token_here"
]);
$out = curl_exec($curl);
return curl_errno($curl);
...然后我总是收到 CURL 7 错误。
发现这个问题正是 Docker 的本质:http://localhost:8086 ((
将 URL 更改为 http://influx:8086 时 - 得到 CURL 6。
如何通过 PHP CURL 使用 Docker 容器?
ssfes f sd e fds ef ds eff sde fds ef ds ef ds ef fefes fesfegesgessgesgdse ggdsse gdse gdsegds Eggges gestt sdgesgeggegsdsegdse gdsegggesdg eeggge shessss hsh hs shshshssssdeesgd e ewwe h sahfa dha dosadi sahdhds akkksad wqods awidq shqwod ashwi dahhdsa oods awhqd sagf sair wrr raws dwha rhs rahd asshhra sshdw arhsa hw sahasd ahsa bfs gi giisa foa eshabf saoeps ifpw shf wasfh fashaf safjasjd has gosaig ah sgasg asgoash gRd sas cashc acc A dashd saahfsa fsagias ag saghaigha skgs igsahg sgiahgias gisahgias gisa hgihsagih saigh 赛加斯 gsa hgC fhsaihfisa f afhsa ffhsa fasih fsia fsaih fsa fasi fodas dlaksd adsoid I fsahjkfsa fhsajwoif sanw fsioa wfhshfa awfis ahfwwi fisa fiah wif sia f wf as S dasd ahdsiaw dsawid M.