Dockerfile for wordpress

I am looking to build and run wordpress website using Dockerfile, but unable to do it.
can anyone help me to find the correct syntax for the Dockerfile to build the image.

?

But why not use the official wordpress image instead of building your own?

Tried building the image on my own but not able to
i am using below Dockerfile :

FROM ubuntu:latest
RUN apt-get update && apt-get install -y tzdata && apt-get install software-properties-common -y --no-install-recommends &&\
    add-apt-repository ppa:ondrej/php -y && apt-get install -y --no-install-recommends &&\
    apt-get install -y nginx php7.4 \
    php7.4-fpm \
    php7.4-mbstring \
    php7.4-bcmath \
    php7.4-xml \
    php7.4-xmlrpc \
    php7.4-zip \
    php7.4-sqlite3 \
    php7.4-mysql \
    php7.4-pgsql \
    php7.4-imap \
    php7.4-readline \
    php7.4-phpdbg \
    php7.4-curl \
    php7.4-dev \
    php-pear \
    php-ssh2 \
    php-yaml \
    php-memcached \
    php-redis \
    php-apcu \
    php-xdebug \
    php-xhprof \
    curl \
    unzip
RUN apt-get clean -y && apt-get -y autoremove
RUN rm -rf /tmp/* /var/tmp/* /usr/share/doc/*
RUN sed -i 's/;pcre.jit=1/pcre.jit=0/g' /etc/php/7.4/cli/php.ini && \
    sed -i 's/;pcre.jit=1/pcre.jit=0/g' /etc/php/7.4/fpm/php.ini
RUN service nginx start && service php7.4-fpm start
RUN rm /var/www/html/index.nginx-debian.html &&\
    rm -f /etc/nginx/sites-available/default &&\
    rm -f /etc/nginx/sites-enabled/default
ADD ./wordpress/ /var/www/html/
ADD default /etc/nginx/sites-available/
ADD php.info /var/www/html/
RUN ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
RUN service php7.4-fpm reload
RUN /usr/sbin/nginx
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80

But still not able to build the image.

What error do you get?

Also, since there is alot of php-heavy stuff in your dockerfile, maybe switch to the php-apache image, its a bit easier to install php modules

I am trying to install the basic wordpress website as i did on my localhost.

below is the error i am getting

Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/s/strip-nondeterminism/libfile-stripnondeterminism-perl_1.7.0-1_all.deb Undetermined Error [IP: 91.189.88.142 80]

i also tried below two commands to directly pull and run the wordpress website :

docker run --name db -p 90:3306 --restart=always --network wp-mysql-network -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=P@ssw0rd -v mysql-demo3:/var/lib/mysql -d mysql:latest

docker run -d --name wp-site1 --link db -p 85:80 -e WORDPRESS_HOST=db:90 --network wp-mysql-network -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=P@ssw0rd -v wp-data-demo3:/var/www/html wordpress:latest

but then this error comes :

Error establishing a database connection on the browser

When using -p, its only for external access and in, between containers its still the main port.
so in your wordpress host, it should be db:3306, or just … db as 3306 is the default port

1 Like