How to enable theme on WordPress on Docker

I am using docker to run a develop environment for several wordpress themes / plugins. However, I can’t figure out how to enable my themes automatically on container creation. Normally I would just use wp-cli for this. I have created a custom image that extends the official wordpress image, but I can’t figure out how to make the wp-cli commands run after the /var/www/html folder get’s setup (I think this is created by the wordpress image entrypoint script). If I put the commands in a “RUN” command in the dockerfile, the commands just fail since the /var/www/html directory is empty. However, if I connect to the container once it is setup, the directory is populated, and wp-cli works just fine. How can I run a command after the from the parent image is run?

Here is the content of my dockerfile (which does not work):

  • How do I connect to gcloud sql with gcloud sql proxy from GKE
  • Run docker command with JSch
  • Can't connect nodejs and mysql in same docker
  • Configuring Spark Job Server to work with cluster
  • Install nginx dynamic module using docker compose
  • ssh from docker container to internet, got stuck and no errors produced
  • FROM wordpress
    COPY docker-install/wp-cli.phar /usr/local/bin/wp
    WORKDIR /var/www/html
    RUN chmod u+x /usr/local/bin/wp
    RUN /usr/local/bin/wp core install --title="Test WP Site" --admin_user=admin --admin_password=something  --url=localhost:8080 --allow-root
    RUN /usr/local/bin/wp theme activate mytheme --allow-root

  • How to run docker containers in their network with an external gateway?
  • Docker not installing composer dependencies after image built
  • access docker VM in private network (docker-machine)
  • Is it possible to mount folder from container to host machine?
  • When does the docker volume become available for CMD script?
  • Why connect to Google Cloud SQL failed inside Docker container but success outside Docker container?
  • One Solution collect form web for “How to enable theme on WordPress on Docker”

    The short answer: You can’t. The ENTRYPOINT and CMD is are used at Docker container runtime, not build time. In this case, the WordPress environment is actually started at container runtime so you can’t interact with it during a build.

    The long answer: You might be able to help accomplish your goals by using Docker Compose to create two services, one for WordPress and another for the WordPress CLI variant (see the cli tags at with a volumes_from the first one. Then, you could use docker-compose run cli-service wp-cli command to run your commands.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.