I try to build a web stack with docker using "php, mariadb, ngnix, composer"
I try to use only container from official repositories
following my docker-compose.yml
version: '2'
services:
nginx:
image: nginx
container_name: nginx
ports:
- "8000:80"
mariadb:
image: mariadb
container_name: mariadb
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_USER : root
MYSQL_ROOT_PASSWORD: root
php:
image: php:fpm
container_name: php
ports:
- "80:80"
volumes:
- ./php/:/var/www/html/
composer:
image: composer
container_name: composer
volumes_from:
- php
working_dir: /var/www/
volumes:
- ./composer2:/app
this docker-compose work correctly, but I don't understand why composer down quickly after 'docker-compose up -d'
PS:My first goal is to use this stack for symfony2 or silex
The composer container is ended imediatelly becuase it's not intended to run as a "daemon". In case you don't provide any command, the composer, simply said, has nothing to do. Anyways, if it has "something to do", then it executes it and ends.
You can use it through interactive shell like this:
docker run --rm --interactive --tty --volume $PWD:/app composer install
More examples are in the "Using" section here: https://hub.docker.com/_/composer/
Related
I am trying to create a basic wordpress/mariadb/wpcli docker container stack. All works as expected, except that the wpcli service fails at startup time with this error turning up in the logs:
"Error: Error establishing a database connection."
To be clear, I can access the wordpress site just fine after allowing enough time for the db and wp containers to spin up. But the wpcli container fails.
Here is my docker-compose.yml:
version: '3.9'
services:
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:latest
# If you really want to use MySQL, uncomment the following line
#image: mysql:8.0.27
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
wordpress:
image: wordpress:php8.1
ports:
- 80:80
restart: always
depends_on:
- db
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
wpcli:
image: wordpress:cli-php8.1
# restart: always
depends_on:
- db
- wordpress
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
volumes:
db_data:
wordpress:
My plan for the short term is to develop new themes for an already existing site, so I have the workaround that I can install wpcli directly in the wp container. But that's a pain, and I am new to docker (definitely not new to linux or wordpress) and I don't really want to take time right now to learn how to roll my own container that has both wordpress and wpcli.
Incidentally, I tried the Bitnami wordpress container which has exactly that, but ran into issues mounting volumes on localhost due to those being non-root containers.
Any ideas about how to get the wpcli container from the official wordpress to work?
Thanks in advance for your help!
I have been working in this bitnami-wordpress-docker and still stuck on configuration. I have seen few tutorials in which the command docker-compose up -d create bunch of files inside the folder and later localhost:8000 lands to the admin part of the wordpress. But things are not being simple for me.
Here is my docker-compose.yml file.
version: '3'
services:
mariadb:
user: root
image: 'bitnami/mariadb:10.3'
volumes:
- 'mariadb_data:/bitnami'
restart: always
environment:
- MARIADB_USER=bn_wordpress
- MARIADB_DATABASE=bitnami_wordpress
- ALLOW_EMPTY_PASSWORD=yes
networks:
- wpsite
wordpress:
image: 'bitnami/wordpress:latest'
ports:
- '8000:80'
restart: always
volumes:
- 'wordpress_data:/bitnami'
depends_on:
- mariadb
environment:
- MARIADB_HOST=mariadb
- MARIADB_PORT_NUMBER=3306
- WORDPRESS_DATABASE_USER=bn_wordpress
- WORDPRESS_DATABASE_NAME=bitnami_wordpress
- ALLOW_EMPTY_PASSWORD=yes
networks:
- wpsite
phpmyadmin:
depends_on:
- mariadb
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: mariadb
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
networks:
wpsite:
volumes:
mariadb_data:
driver: local
wordpress_data:
driver: local
The command I mentioned above is creating containers.
When I try localhost:8000, noting shows. But when localhost:8080 lands me to phpmyadmin page.
Can anybody please tell me how can I setup this Bitnami wordpress using docker. It starts getting frustrating for me.
Thank You.
Under windows, it often happens to me that some ports are occupied;)
I do that:
I start powershell or cmd as admin
running netstat -aon | findstr 8080 the last number is the port
I get TCP 0.0.0.0:8080 0.0.0.0.0 LIETENIN 3428
run taskkill /f /pid 3428
And I'm also using the vscode plugin vscode-docker to use for removing all contaners and images.
Take a look at my example of docker+wordpress+xdebug maybe something will come in handy ;)
I'm new to docker and I'm just trying to create a simple Symfony API. I ran docker-compose up -d which created these containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
071de3320346 willdurand/elk "/usr/bin/supervisor…" About a minute ago Up About a minute 0.0.0.0:81->80/tcp simple-api_elk_1
c24132f645be simple-api_nginx "nginx" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 443/tcp simple-api_nginx_1
37128a03b667 simple-api_php "php-fpm7 -F" About a minute ago Up About a minute 0.0.0.0:9000->9000/tcp simple-api_php_1
aa7738c59891 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp simple-api_db_1
I then took the id from the simple-api_php and ran
docker exec 37128a03b667 composer create-project symfony/website-skeleton symfony-api
It returns:
OCI runtime exec failed: open /tmp/runc-process126262263: permission denied: unknown
here is my docker-compose.travis.yml:
version: '2'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
php:
build: ./php-fpm
expose:
- "9000"
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/var/logs
links:
- db
nginx:
build: ./nginx
ports:
- "80:80"
links:
- php
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
volumes_from:
- php
- nginx
Just don't have enough knowledge to troubleshoot this.
Thanks!!
You should edit your elk service.
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns <-------- remove this line
volumes_from:
- php
- nginx <-------- remove this line
Note: comments are marked with arrow <------
Also, if you still have the same issue - try to remove images and containers and then rebuild them.
// This command will remove all containers and images in your docker-compose.travis.yml file
$: docker-compose down
// Or you can remove container and images manually
$: docker rm container_name
$: docker rmi image_name
I need to build a wordpress container(preferably using dockerfile) which has the following;
Self signed SSL certificate for Apache
Custom wp-config.php
How do I do that through a dockerfile?
I am not into WordPress but it should look something like this.
I have taken the defaults from the official docker hub repo.
Dockerfile:
FROM php:7.1-apache
ADD my.crt /etc/ssl/certs/my.crt
ADD my.key /etc/ssl/private/my.key
ADD wp-config.php /path/to/your/config/wp-config.php
Make sure that the certs are located at the right position for your apache/wordpress config.
stack.yml:
version: '2.0'
services:
wordpress:
build:
context: .
dockerfile: ./Dockerfile
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
Run with:
docker-compose -f stack.yml up --build
I want to set a sendmail_path in WordPress' container and use a sendmail provided by another container. In my case its MailHog.
So this is my docker-compose:
version: '2'
services:
wordpress:
image: wordpress
links:
- db:mysql
- mailhog
ports:
- 80:80
domainname: foo.com
hostname: foo
volumes:
- ./public:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: example
depends_on:
- mailhog
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
I tried executing the command: "echo 'sendmail_path = \"/usr/local/bin/mailhog sendmail\"' > /usr/local/etc/php/conf.d/mail.ini" on WordPress container but it actually prints it...
Does these two have to share the volumes?
PS. I know I can use it as a SMTP server in the APP but I want to deal with it in more automated way.
You don't have MailHog installed in the WordPress container, so the path /usr/local/bin/mailhog doesn't exist.
What you want to do is to send emails via sendmail and those emails must be caught by MailHog. To do this, you must extend the WordPress Dockerfile:
FROM wordpress
RUN curl --location --output /usr/local/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 && \
chmod +x /usr/local/bin/mhsendmail
RUN echo 'sendmail_path="/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025 --from=no-reply#docker.dev"' > /usr/local/etc/php/conf.d/mailhog.ini
Note the --smtp-addr parameter must be in the form <mailhog_hostname>:<mailhog_port>.
Change your docker-compose.yml to build your Dockerfile.
version: '2'
services:
wordpress:
build:
context: ./
dockerfile: ./Dockerfile
links:
- db:mysql
- mailhog
ports:
- 80:80
domainname: foo.com
hostname: foo
volumes:
- ./public:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: example
depends_on:
- mailhog
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
In this example, the Dockerfile you have written must be named "Dockerfile" and must be in the current directory (where you run docker-compose). You can change the path accordingly. You can remove the 1025:1025 ports entry if you don't need to connect to it from the host.
Now the function mail() should work as intended.