1

Im trying to build wordpress theme with docker & docker-compose. The problem that Im having is that Im trying to copy my theme into exposed wp-content folder of docker but for some reason it says there is not such file or directory.

Runing ls command my folder structure looks like this:

wp-content // available only after docker compose finishes
theme
dockerFile
docker-compose.yaml

Here is how my docker-compose.yaml file looks like

version: '3'

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password 
    networks:
      - wpsite
  # Wordpress
  wordpress:
    build: .
    depends_on:
      - db
    ports:
      - '8000:80'
    restart: always
    volumes:
      - ./wp-content/:/var/www/html/wp-content
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:

And here how my DockerFile looks like

FROM wordpress:latest
RUN echo "Install wordpress"
COPY ./giveaway_theme ./wp-content/themes
RUN echo "Copy theme to wp-content folder"

Looks like im somehow inside container, because when I run ls command it shows nothing, So my question is is there any way that I can copy theme into wp-content folder after docker compose finishes ??

Loki
  • 1,064
  • 2
  • 26
  • 55

1 Answers1

3

In your Docker file you are not setting a WORKDIR, hence your COPY command is relative to root (/). So it copies your theme to /wp-content/themes.

Before the COPY command you can set:

WORKDIR /var/www/html

This would fix your Dockerfile. And you will ship the image with the theme already inside.

However

You are already mapping a local copy of wp-content into the a volume. So if you just place your theme in the correct location on your host (inside ./wp-content/themes) then it will be picked up by docker-compose. At that point you don't need the COPY command in the Dockerfile anymore.

Community
  • 1
  • 1
Mihai
  • 9,526
  • 2
  • 18
  • 40
  • How do you mean If I place it inside of ./wp-content/themes that folder structure is created after docker-compose is finished ? @Mihai Could you explain a bit more ? – Loki Feb 07 '20 at 09:03
  • 2
    when you map a volume during docker-compose up, it will create it in local if it doesn't exist. but if it exists, it will mount it inside the container with the same contents from your local host. To understand better, replace your volume with: `./theme:/var/www/html/wp-content/themes` – Mihai Feb 07 '20 at 09:14
  • 1
    Thank you so much, will try it :) – Loki Feb 07 '20 at 09:35