Wordpress Docker将主题复制到暴露的文件夹中 [英] Wordpress docker copy theme into exposed folder

查看:145
本文介绍了Wordpress Docker将主题复制到暴露的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用docker&构建wordpress主题docker-compose。我遇到的问题是我试图将我的主题复制到docker的暴露的wp-content文件夹中,但由于某种原因,它说没有这样的文件或目录。

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.

运行ls命令,我的文件夹结构如下所示:

Runing ls command my folder structure looks like this:

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

这是我的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:

这是我的DockerFile的样子

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"

在容器内看起来有点像im,因为当我运行ls命令时它什么也没显示,
所以我的问题是有什么方法可以将主题复制到wp-content文件夹中docker编写完成后??

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 ??

推荐答案

在您的Docker文件中,您未设置WORKDIR,h因为您的COPY命令是相对于根(/)的。因此它将主题复制到/ wp-content / themes。

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.

在COPY命令之前,您可以设置:

Before the COPY command you can set:

WORKDIR /var/www/html

这将修复您的Dockerfile。

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

您已经将wp-content的本地副本映射到卷中了。 。因此,如果您只是将主题放置在主机上的正确位置(在./wp-content/themes内部),则它将由docker-compose拾取。那时,您不再需要Dockerfile中的COPY命令。

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.

这篇关于Wordpress Docker将主题复制到暴露的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆