Cannot login with wp-cli generated user wordpress behind reverse proxy - wordpress

Hello fellows I have made a custom wordpress image located there: https://github.com/ellakcy/wordpressWithPlugins
And on entrypoint script I am using wp-cli in order to generate a custom user in order to preinstall plugins. But I cannot login to the control panel with the generated user from wp-cli.
Do you have any Idea how to fix it?
The entrypoint of the script is the following: https://github.com/ellakcy/wordpressWithPlugins/blob/master/docker-entrypoint.sh
I run the containers with these commands: (for development purpose)
docker run --name wpdb -e MYSQL_ROOT_PASSWORD=1234 -d mariadb
docker run --name mywordpress --link wpdb:mysql -p 8080:80 -ti wp
And I am using apache as reverse proxy in order to access the wordpress running in the mywordpress container:
<VirtualHost *:80>
ProxyPass / http://172.17.0.3/
ProxyPassReverse http://172.17.0.3/ /
</Virtualhost>
(In place of 172.17.0.3 can be the ip of the container running the wordpress)
Edit 1
I managed to login by setting up a network:
docker network create --subnet="172.19.0.0/16" wordpress_default
And setting the custom ips to the coontainers. (Also I set some Enviromental variables too.)
RUN MYSQL/MARIADB
docker run --name wpdb --net wordpress_default --ip 172.19.0.2 -e MYSQL_ROOT_PASSWORD=1234 -d mariadb
run wordpress docker with some extra enviiromental variables
docker run --name mywordpress --net wordpress_default --ip 172.19.0.3 --link wpdb:mysql -e WORDPRESS_ADMIN_PASSWORD=1234 -e WORDPRESS_ADMIN_EMAIL=pc_magas#openmailbox.org -e WORDPRESS_URL=172.19.0.3 -p 8080:80 -ti wp
And visiting the wordpress site via the ip given oon the second coommand. But I still have problems with the local apache running as reverse proxy.

In the end just manually setting the machine's ip as url works like a charm.
docker run --name wpdb --net wordpress_default --ip 172.19.0.2 -e MYSQL_ROOT_PASSWORD=1234 -d mariadb
run wordpress docker with some extra enviiromental variables
docker run --name mywordpress --net wordpress_default --ip 172.19.0.3 --link wpdb:mysql -e WORDPRESS_ADMIN_PASSWORD=1234 -e WORDPRESS_ADMIN_EMAIL=pc_magas#openmailbox.org -e WORDPRESS_URL=172.19.0.3 -p 8080:80 -ti wp
All I had to do wat to set the following vhost to my apache:
<VirtualHost *:80>
RequestHeader set X-Forwarded-Proto "http"
ProxyPass / http://172.19.0.3/
ProxyPassReverse http://172.19.0.3/ /
</Virtualhost>
(Perhaps for production may need some changes)

Related

Wordpress install with Docker doesn't work

I'm completely beginner with Docker and I'm trying to install wordpress (without database) from a base ubuntu 20.04 image with docker. I'm using apache server for this.
Here is my wordpress2_ms.dockerfile:
FROM ubuntu:20.04 as baseimage
SHELL ["/bin/bash", "-c"]
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y wget tar curl sudo systemctl
RUN apt install -y php libapache2-mod-php
RUN wget -c http://wordpress.org/latest.tar.gz
RUN tar xzvf latest.tar.gz -C /var/www/html
RUN sudo chown -R www-data.www-data /var/www/html/wordpress
FROM baseimage as wordpressapp
COPY wordpress.conf /etc/apache2/sites-available/
WORKDIR /etc/apache2/sites-available
RUN sudo a2ensite wordpress.conf
RUN sudo a2dissite 000-default.conf
RUN sudo systemctl reload apache2
EXPOSE 80
For this, we have to place a context folder beside this wordpress2_ms.dockerfile, and inside this context folder we need the following wordpress.conf file:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/wordpress
ServerName localhost
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
The building command: sudo docker build -t wordpress:1.0 -f ./wordpress2_ms.dockerfile --target wordpressapp ./context/
The run command: sudo docker run -td --name wordpress_cont -p 8081:80 wordpress:1.0
After the run command I get the log that the wordpress has started at port 80 of the container, but nothing is happening at 8081 port of my host machine.
I would appreciate any help. Thanks in advance!

how to setting docker container (wordpress) only using domain to visit?

I build a wordpress blog by docker.Using the 8080 port.But i want to only using my domain to visit the blog ,the ip and the other domain can't .
I try to use caddy proxy the 8080 port to my domain , but it did not work.
So i try to edit the apache.conf , but when i exec into the container,i found there didn't has vi ,so i can't edit anything.
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7
docker run --name some-wordpress --link some-mysql:mysql -p 8080:80 -d wordpress
I just want to know how i can set only using domain to visit my blog .
Could some one tell me ?

Change mapped ip in wordpress docker container

I'm a little bit newbie with Docker. The problem is my server provider changed the public IP recently. When I ran my wordpress container I used the following:
docker run -e WORDPRESS_DB_PASSWORD=xxx --name wordpress-xx --link wordpressdb-xx -p 185.166.xx.xx:8081:80 -v "$PWD/docker/data/wordpress/xx":/var/www/html -d wordpress
How can I change the old IP in order to assign the new one in a container that is already running?
Is it possible to run this containers with localhost IP? For example:
docker run -e WORDPRESS_DB_PASSWORD=xxx --name wordpress-xx --link wordpressdb-xx -p 127.0.0.1:8081:80 -v "$PWD/docker/data/wordpress/xx":/var/www/html -d wordpress
You can also try to save the current container as an image using docker commit and then run the image as a new container with the new IP.
If you have only a single network interface just pass the port only. You can also use the 127.0.0.1 address
See https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p-expose

Development environment for Wordpress with Docker incl. FTP access

I would like to know if it is possible to provide a local development environment for Wordpress, where the data can be uploaded via FTP?
I already got the official Docker image of Wordpress running:
docker run --name wordpress-db -e MYSQL_ROOT_PASSWORD=admin -p 3306:3306 -d mysql
docker run --name wordpress --link wordpress-db:mysql -p 8080:80 -d wordpress
Next, I'm trying to use an FTP Docker image. After a short search, I chose metabrainz/docker-anon-ftp. But I do not have to continue using this image if there are better ones. I have extended my commands as follows:
docker run --name wordpress --link wordpress-db:mysql -p 8080:80 -v /wordpress-volume:/var/www/html/wp-content -d wordpress
docker run --name wordpress-ftp -p 20-21:20-21 -p 65500-65515:65500-65515 -v /wordpress-volume:/var/www/html/wp-content -d metabrainz/docker-anon-ftp
Now I have the problem that the FTP server is reachable, but does not provide me with any content.
What did I do wrong? Can someone give me the commands with which I can upload files (from my IDE) into Wordpress via FTP?

Docker Container Networking with Docker-in-Docker

I would like to network with a child docker container from a parent docker container, with a docker-in-docker setup.
Let's say I'm trying to connect to a simple Apache httpd server. When I run the httpd container on my host machine, everything works fine:
asnyder:~$ docker run -d -p 8080:80 httpd:alpine
asnyder:~$ curl localhost:8080
<html><body><h1>It works!</h1></body></html>
But when I do the same from a docker-in-docker setup, I get a Connection refused error:
asnyder:~$ docker run -d --name mydind --privileged docker:dind
asnyder:~$ docker run -it --link mydind:docker docker:latest sh
/ # docker run -d -p 8080:80 httpd:alpine
/ # curl localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused
I have tried a couple alterations without luck. Specifying the 0.0.0.0 interface:
asnyder:~$ docker run -d --name mydind --privileged docker:dind
asnyder:~$ docker run -it --link mydind:docker docker:latest sh
/ # docker run -d -p 0.0.0.0:8080:80 httpd:alpine
/ # curl 0.0.0.0:8080
curl: (7) Failed to connect to 0.0.0.0 port 8080: Connection refused
Using the host network:
asnyder:~$ docker run -d --name mydind --privileged docker:dind
asnyder:~$ docker run -it --link mydind:docker docker:latest sh
/ # docker run -d --network host httpd:alpine
/ # curl localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused
Surprisingly, I was unable to find any existing articles on this. Does anyone here have some insight?
Thanks!
There are pros and cons for both DinD and bind mounting the Docker socket and there are certainly use cases for both. As an example, check out this set of blog posts, which does a good job of explaining one of the use cases.
Given your example docker-in-docker setup above, you can access Apache httpd server in one of two ways:
1) From inside the docker:dind container, it will be available on localhost:8080.
2) From inside the docker:latest container, where you were trying to access it originally, it will be available on whatever hostname is set for the docker:dind container. In this case, you used --name mydind, therefore curl mydind:8080 would give you the standard Apache <html><body><h1>It works!</h1></body></html>.
Hope it makes sense!
Building upon Yuriy's answer:
2) From inside the docker:latest container, [...] it will be available on whatever hostname is set for the docker:dind container. In this case, you used --name mydind, therefore curl mydind:8080 [...]
In the Gitlab CI config, you can address the DinD container by the name of its image (in addition to the name of its container, which is auto-generated):
Accessing the services
Let’s say that you need a Wordpress instance to test some API integration with your application.
You can then use for example the tutum/wordpress image in your .gitlab-ci.yml:
services:
- tutum/wordpress:latest
If you don’t specify a service alias, when the job is run, tutum/wordpress will be started and you will have access to it from your build container under two hostnames to choose from:
tutum-wordpress
tutum__wordpress
Using
service:
- docker:dind
will allow you to access that container as docker:8080:
script:
- docker run -d -p 8080:80 httpd:alpine
- curl docker:8080
Edit: If you'd prefer a more explicit host name, you can, as the documentation states, use an alias:
services:
- name: docker:dind
alias: dind-service
and then
script:
- docker run -d -p 8080:80 httpd:alpine
- curl dind-service:8080
Hth,
dtk
I am very convinced that #Yuriy Znatokov's answer is what I want, but I have understood it for a long time. In order to make it easier for later people to understand, I have exported the complete steps.
1) From inside the docker:dind container
docker run -d --name mydind --privileged docker:dind
/ # docker run -d -p 8080:80 httpd:alpine
/ # curl localhost:8080
<html><body><h1>It works!</h1></body></html>
2) From inside the docker:latest container
docker run -d --name mydind --privileged docker:dind
docker run -it --link mydind:docker docker:latest sh
/ # docker run -d -p 8080:80 httpd:alpine
/ # curl mydind:8080
<html><body><h1>It works!</h1></body></html>

Resources