I'm trying to setup a docker-compose system where I'd like to copy dev tools to /usr/local/bin/ on startup.
Thats my docker-compose.yml:
version: '3'
services:
web:
build: docker/container/nginx
ports:
- 4000:80
volumes: &m2volume
- ./src:/var/www/html/
- ./docker/data/bin/:/usr/local/bin/
- ~/.composer:/var/www/.composer
networks: &m2network
- www
links:
- "php"
- "mariadb:mysql"
mariadb:
image: mariadb
ports:
- 8001:3306
networks: *m2network
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: magento2
MYSQL_DATABASE: db
MYSQL_USER: magento2
MYSQL_PASSWORD: magento2
volumes:
- ./docker/container/db/docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/
- ./docker/container/db/conf.d:/etc/mysql/conf.d
- ./docker/data/mariadb:/var/lib/mysql
php:
build: docker/container/fpm
volumes: *m2volume
networks: *m2network
networks:
www:
if I leave - ./docker/data/bin/:/usr/local/bin/ in it, I get an error:
ERROR: for m2_php_1 Cannot start service php: oci runtime error: container_linux.go:262: starting container process caused "exec: \"docker-php-entrypoint\": executable file not found in $PATH"
Starting m2_mariadb_1 ... done
ERROR: for php Cannot start service php: oci runtime error: container_linux.go:262: starting container process caused "exec: \"docker-php-entrypoint\": executable file not found in $PATH"
If I uncomment it, all works fine.
What am I doing wrong here?
If i understand this correctly, and mapping the volume ./docker/data/bin/:/usr/local/bin/ is causing an exception, then that's probably because of the entrypoint defined in the mariadb image.
More to the point, you're overwriting the /usr/local/bin container folder, which probably contains an executable used in the entrypoint. When that disappears, you get an error.
Related
I have the following docker-compose file. When I try to up the file the mysql container start, but the php one keeps on restarting. When I look at the logs all I get is "interactive shell" constantly. Any idea why this is happening?
---
version: "3"
services:
web:
image: php:alpine3.12
restart: unless-stopped
volumes:
- web_Data:/var/www/html
ports:
- 80:80
- 443:443
mariadb:
image: mariadb
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: Password1
volumes:
- mariadb_Data:/var/lib/mysql
ports:
- 3306:3306
volumes:
web_Data:
mariadb_Data:
driver: local
The reason you are getting Interactive shell message it's because that's an output of php:alpine3.12 image and since your container is constantly restarting, it keeps logging that message.
I don't really know PHP but it looks like the command that the image tries to do is docker-php-entrypoint php -a, and that starts an interactive shell, am I right?
If that is the case, then you need to run it in interactive mode. To do that, in docker-compose.yml file, just add the last 2 lines:
web:
image: php:alpine3.12
restart: unless-stopped
volumes:
- web_Data:/var/www/html
ports:
- 80:80
- 443:443
stdin_open: true
tty: true
Then your container will keep running and you will be able to interact with it.
The reason is that you are using an inappropriate PHP image. If you want to run PHP with a web server then you should use one of:
php:<version>-fpm
php:<version>-apache
See Image Variants in the Docker documentation.
I have issue after last docker update (seems so) on Windows 10 (local development). When I changed files in PhpStorm (and in another editors - Sublime, Notepad+), after a while, files inside container didn't receive changes.
Steps that can help for a while:
If I completely shut down all containers and after that arise them again. docker-compose down && docker-compoes up
If I get into php-fpm container and for file that not changed ran touch file.php (this file will be immidiatly changed).
What I tried and it didn't help:
I restarted php-fpm and nginx containers docker-compose restart php-fpm nginx (Yes it's strange, because down|up for all container helped)
I changed inside PhpStorm setting Use Safe write(save changes for temporary file first)
Also I checked inode for file inside container. With ls -lai file.php. Before changes worked and after they broked I had the same inode number. There is no determined number of changes I must to do to break syncing, it's random, sometime 2 changes enough.
I have:
Docker version 19.03.5, build 633a0ea
docker-compose version 1.25.2, build 698e2846
docker-compose.yml
version: '3'
services:
nginx:
container_name: pr_kpi-nginx
build:
context: ./
dockerfile: docker/nginx.docker
volumes:
- ./:/var/www/kpi
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./docker/nginx/fastcgi.conf:/etc/nginx/fastcgi.conf
ports:
- "8081:80"
links:
- php-fpm
networks:
- internal
php-fpm:
container_name: pr_kpi-php-fpm
build:
context: ./
dockerfile: docker/php-fpm.docker
volumes:
- ./:/var/www/kpi
links:
- kpi-mysql
environment:
# 192.168.221.1 -> host.docker.internal for Mac and Windows
XDEBUG_CONFIG: "remote_host=host.docker.internal remote_enable=1"
PHP_IDE_CONFIG: "serverName=Docker"
networks:
- internal
mailhog:
container_name: pr_kpi-mailhog
image: mailhog/mailhog
restart: always
ports:
# smtp
- "1025:1025"
# http
- "8025:8025"
networks:
- internal
kpi-mysql:
container_name: pr_kpi-kpi-mysql
image: mysql:5.7
command: mysqld --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
volumes:
- ./docker/storage/kpi-mysql:/var/lib/mysql
environment:
# We must change prod secrets, this is not good approach
- "MYSQL_ROOT_PASSWORD=pass"
- "MYSQL_USER=user"
- "MYSQL_PASSWORD=user_pass"
- "MYSQL_DATABASE=kpi_db"
ports:
- "33061:3306"
networks:
- internal
kpi-npm:
container_name: pr_kpi-npm
build:
context: ./
dockerfile: docker/npm.docker
volumes:
- ./:/var/www/kpi
- /var/www/kpi/admin/node_modules
ports:
- "4200:4200"
networks:
- internal
tty: true
# For xdebug
networks:
internal:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.221.0/28
P.S. There is opened issue:
https://github.com/docker/for-win/issues/5530
P.P.S. We need to update Docker from 2.2.0.0 to 2.2.0.3, Seems it's fixed
I have a separate container for syncing my folder:
app:
image: httpd:2.4.38
volumes:
- ./:/var/www/html
command: "echo true"
I just use the basic apache image, you could use anything really though. Then in my actual containers, I use the following volumes_from key:
awesome.scot:
build: ./build/httpd
links:
- php
ports:
- 80:80
- 443:443
volumes_from:
- app
php:
build: ./build/php
ports:
- 9000
- 9001
volumes_from:
- app
links:
- mariadb
- mail
environment:
APPLICATION_ENV: 'development'
I've never had an issue using this set up, files always sync fast, and I have tested both on Mac OSX and MS Windows.
If you're interested, here is my full LAMP stack on Github https://github.com/delboy1978uk/lamp
I have the same issue on Windows10 since 31st Jan.
I have commented a line in PhpStorm and checked it in the container using vim.
The changes were not there.
If I run docker-compose down and up, the changes go in the container.
Docker version 19.03.5, build 633a0ea
docker-compose version 1.25.4, build 8d51620a
Nothing changed in my docker-compose.yml since 2018.
I have this docker stack running nginx, php, and mariadb.
Now I want to add NodeJS in order to migrate my platform to services, one at the time.
I'm trying to add node in the same way I added php,but when I run "docker-compose up", nodejs appears "Exited with code 254".
It appears to be a ENOET error related with my package.json file, but I'm already coping my file into the container, also if I run everything less nodejs, when I access my nginx container the package.json appears in the route it means to be, so I don't know why I'm seeing this error.
Here is my docker-compose.yml
nginx:
image: tutum/nginx
ports:
- "80:80"
- "8080:8080"
# - "8081:8081"
# - "8082:8082"
# - "8083:8083"
# - "8090:8090"
links:
- nodejs
- phpfpm
- mariadb
volumes:
- ./public/leal-api:/var/www
- ./nginx/default:/etc/nginx/sites-available/default
- ./nginx/default:/etc/nginx/sites-enabled/default
- ./public:/usr/share/nginx/html
nodejs:
command: npm start
build: ./node
ports:
- "3000:3000"
links:
- mariadb
volumes:
- ./public/leal-api:/var/www
phpfpm:
build: ./php
ports:
- "9000:9000"
links:
- mariadb
volumes:
- ./public:/usr/share/nginx/html
mariadb:
image: mariadb
environment:
MYSQL_DATABASE: leal
MYSQL_USER: lealadm
MYSQL_PASSWORD: leal2015*
MYSQL_ROOT_PASSWORD: LealColombia2017!
ports:
- "3306:3306"
And here is the Dockerfile of the nodejs
FROM node:7.10
VOLUME ["/var/www"]
# WORKDIR /src
WORKDIR /var/www
# COPY . /src
# RUN npm install
# RUN npm install -g nodemon #hmm idk
EXPOSE 3000
CMD ["npm", "start"]
Thanks in advance for any help that you can provide.
I use this to set up nginx for PHP:
nginx:
image: nginx:latest
ports:
- 8080:80
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./code:/code
But how about Apache? How can I set up Apache + PHP in docker-compose.yml?
Following this guide:
version: '2'
services:
php:
build: php
ports:
- "80:80"
- "443:443"
volumes:
- ./php/www:/var/www/html
Error:
ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.
Any ideas? I'm on Xubuntu 16.04.
EDIT:
After managing to upgrade docker-compose to 1.9, I try with this file below:
version: '2'
services:
php:
build: php
expose:
- 9000
volumes:
- ./php/www:/var/www/html
apache2:
image: webdevops/apache:latest
args:
- PHP_SOCKET=php:9000
volumes:
- ./php/www:/var/www/html
ports:
- 80:80
- 443:443
links:
- php
Error:
$ sudo docker-compose up -d
Building php
ERROR: Cannot locate specified Dockerfile: Dockerfile
Docker is such as pain!
Any ideas how to fix this?
I would choose webdevops dockerized apache, because it has simple configuration:
version: '2'
services:
php:
build: php
expose:
- 9000
volumes:
- ./php/www:/var/www/html
apache2:
image: webdevops/apache:latest
args:
- PHP_SOCKET=php:9000
volumes:
- ./php/www:/var/www/html
ports:
- 80:80
- 443:443
links:
- php
Since the example above does not work, here is a different approach:
docker-compose.yml
version: '3.1'
services:
php:
image: php:apache
ports:
- 80:80
volumes:
- ./php/www:/var/www/html/
Launch the server with
docker-compose up
We need to create a new folders /php/www in current path
Create a file under php folder save as "Dockerfile" which contains as below without quote
"FROM php:5.6-apache
RUN docker-php-ext-install mysqli"
Copy your docker-compose.yml file in your current folder where your "php" folder has.
Create a sample file "index.php" under www folder (/php/www/index.php)
Run in command prompt docker-compose up -d
Open your browser type "localhost" you can see your sample file results.
Note: Above steps as per above mentioned docker-compose.yml file.
You can check this question.
If you use build instead of image, then you need "Dockerfile". Dockerfile would be use as configuration file for building image.
You maybe miss part in guide, where you should create file with name "Dockerfile" inside directory "php". Directory "php" must be in the same directory, where your "docker-compose.yml". In "docker-compose.yml" you have this line.
build: php
The line mean, that configuration file (by default: "Dockerfile") is inside of directory "php". So you should create directory "php" and file "Dockerfile" inside of it.
This is "Dockerfile" from your guide.
FROM php:5.6-apache
RUN docker-php-ext-install mysqli
docker-compose.yml reference version 2
Dockerfile reference
I found an elegant way to dynamically configure the ports and other parameters: In apache2's configuration files you can reference environment variables.
#/etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
#APACHE_HTTP_PORT_NUMBER:80
#APACHE_HTTPS_PORT_NUMBER:443
Listen ${APACHE_HTTP_PORT_NUMBER}
<IfModule ssl_module>
Listen ${APACHE_HTTPS_PORT_NUMBER}
</IfModule>
<IfModule mod_gnutls.c>
Listen ${APACHE_HTTPS_PORT_NUMBER}
</IfModule>
you can set the variables in Dockerfile or docker-compose.yml
You can set a directory with diferente Dockerfiles an declare in each service:
...
image: php:custom
build:
context: .
dockerfile: ./dockerfiles/Dockerfile-php
...
I have created a working example of PHP, APACHE, MYSQL, and PHPMYADMIN for PHP developers. You may find it useful if you need the original old-school working style. Please note that I am using port 8080 for my website and port 8081 for PHPMyAdmin. You can change these as you like.
version: '3.8'
services:
php-apache-environment:
container_name: php-apache
image: php:7.4-apache
volumes:
- ./php/src:/var/www/html/
ports:
- 8080:80
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: ezapi
MYSQL_USER: root
MYSQL_PASSWORD: password
ports:
- "6033:3306"
volumes:
- dbdata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
volumes:
dbdata:
I've got a database backup bundle (https://github.com/dizda/CloudBackupBundle) installed on a Symfony3 project using Docker, but I can't get it to work due to it either not finding PHP or not finding MySQL
When I run php app/console --env=prod dizda:backup:start via exec, run, or via cron. I get mysqldump command not found error through the PHP image, or PHP not found error from the Mysql/db image.
How do I go about running a php command that then runs a mysqldump command.
My docker-compose file is as follows:
version: '2'
services:
web:
# image: nginx:latest
build: .
restart: always
ports:
- "80:80"
volumes:
- .:/usr/share/nginx/html
links:
- php
- db
- node
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
php:
# image: php:fpm
restart: always
build: ./docker_setup/php
links:
- redis
expose:
- 9000
volumes:
- .:/usr/share/nginx/html
db:
image: mysql:5.7
volumes:
- "/var/lib/mysql"
restart: always
ports:
- 8001:3306
environment:
MYSQL_ROOT_PASSWORD: gfxhae671
MYSQL_DATABASE: boxstat_db_live
MYSQL_USER: boxstat_live
MYSQL_PASSWORD: GfXhAe^7!
node:
# image: //digitallyseamless/nodejs-bower-grunt:5
build: ./docker_setup/node
volumes_from:
- php
redis:
image: redis:latest
I'm pretty new to docker, so and easy improvements you can see feel free t flag...I'm in the trial and error stage!
Your image that has your code should have all the dependencies needed for your code to run.
In this case, your code needs mysqldump installed locally for it to run. I would consider this to be a dependency of your code.
It might make sense to add a RUN line to your Dockerfile that will install the mysqldump command so that your code can use it.
Another approach altogether would be to externalize the database backup process instead of leaving that up to your application. You could have some container that runs on a cron and does the mysqldump process that way.
I would consider both approaches to be clean.