每当我重新启动时,docker-composer wordpress 都会要求安装

时间:2021-02-15 15:27:52

标签: wordpress ubuntu docker-compose

一切都很好,直到我重新启动我的 Ubuntu 主机。 重启后,WordPress 页面显示全新安装页面。 在主机的本地目录上正确安装了卷。

我只设置了 docker.service 在重启时重启 Docker 服务。 一定有一些我不知道的错误。

至少,如果这种事情再次发生,我该怎么办? 我看到我主机上挂载的所有文件都显示了最新的修改时间, 所以看起来数据是持久的...

(已编辑) 我也像@bilal 在评论中所说的那样尝试了外部 voume,但没有任何区别。 所以,现在我想这可能与启动时的过程有关。就像,而不是停止和启动,它以某种方式向下/向上。但我可能错了。

version: '3.8'

services:

  db:
    container_name: $DB_CONTAINER
    image: mariadb:latest
    restart: always
    volumes:
      - wordpress_db_data:/var/lib/mysql:rw
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: 1
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD

  wp:
    container_name: $WP_CONTAINER
    image: wordpress:latest
    depends_on:
      - db
      - cp
    restart: always
    volumes:
      - wordpress_wp_data:/var/www/html:rw
    environment:
      WORDPRESS_DB_HOST: $DB_CONTAINER
      WORDPRESS_DB_NAME: $DB_NAME
      WORDPRESS_DB_USER: $DB_USER
      WORDPRESS_DB_PASSWORD: $DB_PASSWORD
      WORDPRESS_TABLE_PREFIX: $WP_TABLE_PREFIX
      VIRTUAL_HOST: $VIRTUAL_HOST
      VIRTUAL_PORT: $VIRTUAL_PORT
      LETSENCRYPT_HOST: $VIRTUAL_HOST
      LETSENCRYPT_EMAIL: $LETSENCRYPT_EMAIL
      #LETSENCRYPT_TEST: 'true'

  cp:
    build: composer
    container_name: ${COMPOSER_CONTAINER}
    volumes:
      - wordpress_wp_data:/app/wp-content:rw
    command: composer install

networks:
  default:
    external:
      name: nginx_proxy


volumes:
  wordpress_wp_data:
    name: wordpress_wp_data
  wordpress_db_data:
    name: wordpress_db_data

这是我的音量列表

>  docker volume ls
DRIVER    VOLUME NAME
local     wordpress_db_data
local     wordpress_wp_data

这是我的 docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

1 个答案:

答案 0 :(得分:1)

您应该使用 docker 卷进行持久存储,我的理解是您安装了目录。有关详细信息,请参阅 docker 卷。

所以你的音量部分应该是这样的。

volumes:
      - ./wp_data:/var/www/html:rw
      - wp_data:/wp_data{volume you want to persist}
相关问题