Closed ttodua closed 3 years ago
Hi @ttodua,
I would consider building your own container that includes Wordpress as well as youtube-dl.
An example Dockerfile
would start with:
FROM wordpress:latest
Then, copy/paste the mikenye/youtube-dl
Dockerfile
from line 3 to line 52 (at the time of writing) (so excluding the FROM
WORKDIR
and ENTRYPOINT
lines).
This way, you're installing youtube-dl
and all prerequisites into the wordpress container, resulting in a new container.
You would then update your docker-compose.yml
file as follows:
services:
wordpress:
# image: wordpress:latest
build:
context: /path/to/dir/containing/dockerfile
depends_on:
- db
networks:
- myNetwork
- backend
restart: always
db:
...
networks:
myNetwork:
external: true
backend:
driver: bridge
You should then be able to use docker-compose build
to build the image, and docker-compose up -d
to bring the environment up with the new image. If you need to update the container to the latest version of wordpress/youtube-dl in future, just re-run docker-compose build --no-cache
and then docker-compose up -d
to refresh the environment with the new image.
Once up, you should be able to execute exec('youtube-dl...')
within your PHP.
Also, I don't mean to tell you how to suck eggs, but please be very, very careful passing arguments from website user input to the exec function. At a minimum, please use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands. :)
Hi Mike, thank you for the superb answer! I'll go that way.
You’re very welcome. Please get in touch if you get stuck or need help!
i.e. I use WordPress docker container:
From there (php file), I tried to execute
exec('yt-dl ....')
I get the error in logs, thatyt-dl
doesn't exist (same if do withexec ('youtube-dl ...')
. Can you give a hint, how to make this available in my WP container?