It seems that when i run Docker compose up, docker is not reading from docker-compose.yml.
It seems like it is loading images from cache or i don't think where is finding them.
Bellow is my docker-compose.yml
version: '3'
services:
httpd:
image: httpd:latest
user: root
ports:
- "80:80" # Default Apache port (Default on PHP 7.4)
- "8073:8073" # PHP 7.3 Apache port
- "8074:8074" # PHP 7.4 Apache port
- "8081:8081" # PHP 8.1 Apache port
volumes:
- ./:/var/www/html/myApp/:rw
- ./dev/Docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
restart: on-failure
container_name: httpd
networks:
- mb-frontend
php8.1-fpm:
build: ./dev/Docker/php-fpm/8.1
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php8.1-fpm
networks:
- mb-frontend
- mb-backend
php7.4-fpm:
build: ./dev/Docker/php-fpm/7.4
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.4-fpm
networks:
- mb-frontend
- mb-backend
php7.3-fpm:
build: ./dev/Docker/php-fpm/7.3
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.3-fpm
networks:
- mb-frontend
- mb-backend
db:
image: mariadb:10.3.5
environment:
MYSQL_ROOT_PASSWORD: myPassword
MYSQL_USER: dev
MYSQL_PASSWORD: myPassword
ports:
- "3306:3306"
volumes:
- /root/Bureau/mysql:/var/lib/mysql/:rw
- ./dev/Docker/mariadb/conf.d/:/etc/mysql/conf.d/:rw
- ./dev/Docker/mariadb/config/init.sql:/docker-entrypoint-initdb.d/init.sql
restart: on-failure
container_name: db
networks:
- mb-backend
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
volumes:
- /root/Bureau/phpmyadmin:/var/lib/mysql/
networks:
- mb-backend
depends_on:
- db
redis:
image: redis:6.2
container_name: redis
ports:
- "6379:6379"
networks:
- mb-backend
networks:
mb-frontend:
driver: bridge
mb-backend:
driver: bridge
I commented some images on docker-compose.yml but when i tape the command Docker compose up on terminal, all images even commented images are Up.
Can anyone help me how i force docker to read images from the edited docker-compose.yml
Good practice would be do use:
docker compose down
and then
docker compose up
UPDATE:
Next I would suggest to clean up your containers:
List all containers:
docker ps -a
Remove those you don't want because they might still be in the system
docker rm <CONTAINER ID/NAME>
How to Stop & Remove a running container by ID or Name?
The command is actually docker compose up.
The command docker-compose has been deprecated as of latest version. We can now use docker compose without the hyphen(-).
You can use docker-compose -f <path-to-compose-file> to pass in the compose file.
Example:
docker compose -f docker-compose.yml up
Reference documentation: https://docs.docker.com/compose/reference/
Related
I have a WP project with following docker-compose configuration. When I try to connect my http://localhost to access the installation, I get 500 and I read this in the log:
PHP Fatal error: Uncaught mysqli_sql_exception: Connection refused in /var/www/html/web/wp/wp-includes/wp-db.php
I assume there is something wrong with the ip or the host but the weird thing is that phpmyadmin is working fine, and it connects with mysql without issues.
version: '3.9'
services:
nginx:
image: nginx:latest
container_name: ${APP_NAME}-nginx
ports:
- '80:80'
volumes:
- "./nginx/:/etc/nginx/templates/"
- ./src:/var/www/html:rw,cached
- ./certs:/etc/certs
environment:
- "NGINX_ENVSUBST_TEMPLATE_SUFFIX=.conf"
- "DOMAIN=${DOMAIN}"
depends_on:
- wordpress
restart: always
mysql:
image: mariadb:latest
container_name: ${APP_NAME}-mysql
command: --lower_case_table_names=2
volumes:
- './data/db:/var/lib/mysql:delegated'
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
- MYSQL_DATABASE=${DB_NAME}
restart: always
ports:
- '3307:3306'
wordpress:
build:
context: .
dockerfile: Dockerfile
container_name: ${APP_NAME}-wordpress
volumes:
- ./src:/var/www/html:rw,cached
- ./config/php.ini:/usr/local/etc/php/conf.d/php.ini
environment:
XDEBUG_ENABLED: 1
XDEBUG_CONFIG: remote_host=host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
env_file:
- src/.env
depends_on:
- mysql
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: ${APP_NAME}-phpmyadmin
volumes:
- ./config/phpmyadmin.ini:/usr/local/etc/php/conf.d/phpmyadmin.ini
environment:
PMA_HOST: "${DB_HOST}"
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
ports:
- '8083:80'
links:
- mysql:mysql
mailhog:
container_name: ${APP_NAME}-mailhog
image: mailhog/mailhog
ports:
- "8025:8025"
- "1025:1025"
composer:
image: composer
container_name: ${APP_NAME}-composer
working_dir: /var/www/html
restart: 'no'
volumes:
- ./src:/var/www/html:rw,cached
My wordpress .env, among the other settings, set the host like the following:
DB_HOST="mysql:3307"
But I also tried
DB_HOST="mysql:3306"
or simply
DB_HOST="mysql"
Do you have any suggestions?
Thanks.
your Wordpress Instance and MySQL Instance isn't connected. Try adding networks on the docker-compose.yml
nginx:
...
networks:
- your-network-name
mysql:
...
networks:
- your-network-name
wordpress:
...
networks:
- your-network-name
and on the bottom of the file add:
networks:
your-network-name:
driver: bridge
this is the way to configure docker to be connected each other
This question already has answers here:
From inside of a Docker container, how do I connect to the localhost of the machine?
(41 answers)
Closed 2 years ago.
I am a bit new to docker. I am developing a laravel application, I have my app container running.
Inside app container I want to connect to my locally hosted mongo db server, which is generally localhost:27017.
This is my docker-compose.yml file
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: bns_app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker_files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: bns_web
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./docker_files/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: bns_db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: 12345
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./docker_files/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#REDIS Service
redis:
build:
context: ./docker_files/redis
dockerfile: Dockerfile
container_name: bns_redis
volumes:
- ./docker_files/redis:/data
ports:
- "6379:6379"
networks:
- app-network
# Laravel Echo Server
laravel-echo-server:
build:
context: ./docker_files/laravel-echo-server
dockerfile: Dockerfile
container_name: bns_echo_server
volumes:
- ./laravel-echo-server.json:/var/www/laravel-echo-server.json:ro
ports:
- "6001:6001"
links:
- redis
networks:
- app-network
# PHP-WORKER
php-worker:
build:
context: ./docker_files/php-worker
dockerfile: Dockerfile
container_name: bns_worker
volumes:
- ./php-worker/supervisord.d:/etc/supervisord.d
depends_on:
- app
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
So inside my app container when I run artisan commands such as docker-compose exec app php artisan migrate:fresh --seed mysql tables are migrated successfully but mongo db (which is not in any container but it is in host machine only) documents are not migrate/seeded and I get error :
No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '172.18.0.3:27017']
at /var/www/vendor/mongodb/mongodb/src/functions.php:431
427| // TODO: PHPLIB-476: Read transaction read preference once PHPC-1439 is implemented
428| $readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
429| }
430|
> 431| return $manager->selectServer($readPreference);
432| }
433|
Exception trace:
1 MongoDB\Driver\Manager::selectServer(Object(MongoDB\Driver\ReadPreference))
/var/www/vendor/mongodb/mongodb/src/functions.php:431
2 MongoDB\select_server(Object(MongoDB\Driver\Manager), [])
/var/www/vendor/mongodb/mongodb/src/Database.php:419
Please use the argument -v to see more details.
This is my ENV file:
MONGO_DATABASE=exchange
MONGO_HOST=172.18.0.3 # << This is the IP address of my app container <<
MONGO_PORT=27017
MONGO_USERNAME=
MONGO_PASSWORD=
Please do help me. Where am I going wrong ?
I don't know how but using static ip as 172.17.0.1 worked for me.
Now my ENV file is:
MONGO_DATABASE=exchange
MONGO_HOST=172.17.0.1
MONGO_PORT=27017
MONGO_USERNAME=
MONGO_PASSWORD=
Got reference from here
It must be well documented.
When loading docker-compose up, wordpress loads on the url but the mysqli_connect function is undefined because of the absence of the extension.
I have tried to add the following under the fpm image
command: "docker-php-ext-install mysqli"
I have tried to add a Dockerfile into the directory of the docker-compose.yml file containing
version: "3"
services:
#database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
# webserver
nginx:
image: nginx:latest
ports:
- "8080:80"
links:
- fpm
volumes:
- /Users/connergesbocker/Github/cbgesbocker/dotfiles/root/etc/nginx/conf.d/village.conf:/etc/nginx/conf.d/village.conf
- /Users/connergesbocker/WordPress:/WordPress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8888:8888"
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: wordpress
networks:
- wpsite
fpm:
image: php:5.6.20-fpm
ports:
- "90:9000"
# command: "docker-php-ext-install mysqli"
links:
- db
volumes:
- /Users/connergesbocker/WordPress:/WordPress
working_dir: "/"
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:```
You could customize your dockerfile & add install in it:
Dockerfile:
FROM php:5.6.20-fpm
RUN docker-php-ext-install mysqli
Part of docker-compose.yaml:
fpm:
build: .
image: myphp:1
ports:
- "90:9000"
# command: "docker-php-ext-install mysqli"
links:
- db
volumes:
- /Users/connergesbocker/WordPress:/WordPress
working_dir: "/"
networks:
- wpsite
your override will install the extension but the container will stop after installation because php-fpm will not start by overriding CMD. Replace the command with below one.
command:
- /bin/sh
- -c
- |
docker-php-ext-install mysqli
echo "extension installed.....starting php-fpm........................................"
php-fpm
I want to run php website with letsencrypt and nginx using docker-compose. But it doesn't work. I tried to use other simple web page (not php), like: index.html and it works.
My docker-compose file is based on this project: https://github.com/gilyes/docker-nginx-letsencrypt-sample/blob/master/docker-compose.yml.
Help me, please with php, thanks.
version: "2"
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- "80:80"
- "443:443"
volumes:
- "/etc/nginx/conf.d"
- "/etc/nginx/vhost.d"
- "./website:/usr/share/nginx/html"
- "./volumes/proxy/certs:/etc/nginx/certs:ro"
depends_on:
- fpm
nginx-gen:
restart: always
image: jwilder/docker-gen
container_name: nginx-gen
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
- "./volumes/proxy/templates/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro"
volumes_from:
- nginx
entrypoint: /usr/local/bin/docker-gen -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
letsencrypt-nginx-proxy-companion:
restart: always
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./volumes/proxy/certs:/etc/nginx/certs:rw"
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-gen
fpm:
restart: always
build: ./php-fpm
ports:
- "9000"
container_name: fpm-website
volumes:
- "./website:/usr/share/nginx/html" # folder with web-site
- "./php-fpm/php.ini-production.ini:/usr/local/etc/php/php.ini:ro"
environment:
- VIRTUAL_HOST=website.com
- LETSENCRYPT_HOST=website.com
- LETSENCRYPT_EMAIL=ser#website.com
Here is my Dockerfile for "fpm" container:
FROM php:7.3.2-fpm-alpine
RUN apk update; \
apk upgrade;
RUN docker-php-ext-install mysqli
When I try to open page, I have a message:
502 Bad Gateway
nginx/1.15.12
I'm using Docker to work with php projects.
When I try to change a file of a project on my host machine, PhpStorm says
Could someone please help me to configure the permissions so I could work with the files of my project on my host machine. I'm using Ubuntu 18.04
docker-compose.yml:
version: "3.1"
services:
mysql:
image: mysql:8.0
container_name: symtest-mysql
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=symfony2
- MYSQL_PASSWORD=123
ports:
- "8084:3306"
webserver:
image: nginx:alpine
container_name: symtest-webserver
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8082:80"
php-fpm:
build: phpdocker/php-fpm
container_name: symtest-php-fpm
working_dir: /application
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
UPD: This problem appeared after I generated a new entity inside the docker using bin/console command.