Docker Wordpress - Wrong URL - docker

So I followed the tutorial on this page https://docs.docker.com/compose/wordpress/. Here is the two files I ended up creating and the directory structure
~/project
Dockerfile
docker-compose.yml
wordpress
Dockerfile
FROM orchardup/php5
ADD . /wordpress
docker-compose.yml
web:
build: .
command: php -S 0.0.0.0:8000 -t /wordpress
ports:
- "8000:8000"
links:
- db
volumes:
- .:/wordpress
db:
image: orchardup/mysql
environment:
MYSQL_DATABASE: wordpress
When I try to load up the URL in the browser I get an error
Container logs
[Sat Dec 5 22:32:38 2015] 192.168.99.1:64220 [404]: / - No such file or directory
[Sat Dec 5 22:33:16 2015] 192.168.99.1:64235 [404]: / - No such file or directory
[Sat Dec 5 22:33:45 2015] 192.168.99.1:64243 [404]: / - No such file or directory
[Sat Dec 5 22:33:45 2015] 192.168.99.1:64244 [404]: /favicon.ico - No such file or directory
[Sat Dec 5 22:33:50 2015] 192.168.99.1:64248 [404]: /wp-admin - No such file or directory
[Sat Dec 5 22:35:08 2015] 192.168.99.1:64249 Invalid request (Unexpected EOF)
[Sat Dec 5 22:35:08 2015] 192.168.99.1:64250 Invalid request (Unexpected EOF)
[Sat Dec 5 22:35:08 2015] 192.168.99.1:64251 Invalid request (Unexpected EOF)
[Sat Dec 5 22:44:22 2015] 192.168.99.1:64361 [404]: / - No such file or directory
[Sat Dec 5 22:44:25 2015] 192.168.99.1:64366 [404]: / - No such file or directory
[Sat Dec 5 22:50:00 2015] 192.168.99.1:64442 [404]: / - No such file or directory
[Sat Dec 5 22:50:16 2015] 192.168.99.1:64443 Invalid request (Unexpected EOF)
[Sat Dec 5 22:50:16 2015] 192.168.99.1:64444 Invalid request (Unexpected EOF)
[Sat Dec 5 22:51:30 2015] 192.168.99.1:64477 [404]: / - No such file or directory

You are adding the current directory to /wordpress inside the image. So, the location of the Wordpress files is at /wordpress/wordpress. If you are starting up PHP with a document root of /wordpress then you will want navigate to http://192.168.99.100:8000/wordpress.

Related

Mounting volume on docker-compose, but nginx container sees empty directory

I want to run nginx with docker-compose.
docker-compose.yml:
version: "3.9"
services:
custom-nginx:
image: custom-nginx:latest
network_mode: host
volumes:
- /etc/letsencrypt:/etc/letsencrypt:ro
ports:
- 80:80
- 443:443
restart: always
nginx:
depends_on:
- custom-nginx
image: nginx:alpine
volumes:
- /etc/letsencrypt:/etc/letsencrypt:ro
restart: always
The folder gets mounted but when I look into it from the nginx container it's empty:
/ # ls -al /etc/letsencrypt/
total 4
drwxr-xr-x 2 root root 40 Nov 21 18:00 .
drwxr-xr-x 1 root root 4096 Nov 21 20:07 ..
The custom-nginx Dockerfile is just
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
I assume it has to do with my permissions maybe?
ls -l /etc | grep lets
drwxr-x--- 9 root docker 4096 Nov 21 17:43 letsencrypt
The docker group has rx on the folder recursively. The docker user on the host can see all those folders, and the docker user is running docker in rootless mode.
I was assuming that the root user of the container should see all files the same way as the docker user on the host machine?
What am I missing here?
EDIT: This is the content of /etc/letsencrypt on the host
ls -l /etc/letsencrypt/
total 32
drwx------ 3 root root 4096 Nov 21 17:32 accounts
drwxr-x--- 3 root docker 4096 Nov 21 17:43 archive
-rwx------ 1 root root 207 Nov 12 2021 cli.ini
drwx------ 2 root root 4096 Nov 21 17:43 csr
drwx------ 2 root root 4096 Nov 21 17:43 keys
drwxr-x--- 3 root docker 4096 Nov 21 17:43 live
drwx------ 2 root root 4096 Nov 21 17:43 renewal
drwx------ 5 root root 4096 Nov 21 17:32 renewal-hooks
The container, inside its nginx.conf, only references /etc/letsencrypt/live/<domain_name>fullchain.pem which actually is a link:
/etc/letsencrypt/live/<domain_name>/fullchain.pem -> ../../archive/<domain_name>/fullchain1.pem
But both live and archive folders seem to have the necessary permissions in my opinion...

Redis config doesn't setup on docker

I tried to specify Redis config in the Dockerfile:
FROM redis:7.0.0
EXPOSE 6379
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD ["redis-server", "--include /usr/local/etc/redis/redis.conf"]
But in logs:
redis_1 | 1:C 14 Nov 2022 12:32:28.045 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 14 Nov 2022 12:32:28.045 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 14 Nov 2022 12:32:28.045 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 14 Nov 2022 12:32:28.046 * monotonic clock: POSIX clock_gettime
redis_1 | 1:M 14 Nov 2022 12:32:28.050 * Running mode=standalone, port=6379.
redis_1 | 1:M 14 Nov 2022 12:32:28.051 # Server initialized
And redis config doesn't work
With config I want to disable replica-read-only, which produces "Can't write against read-only replica" errors.

Docker volume lost files rights in container?

Here is my docker-compose.yml :
version: '2'
services:
backgestionpersonne_TEST_CBS:
image: my-registry.compagny.com/my_repo/TEST_CBS:${TAG_VERSION}
container_name: TEST_CBS
restart: always
ports:
- 5555:80
networks:
- traefik
volumes:
- '/etc/pki/ca-trust/source/anchors/cert_Subordinate_CA.pem:/usr/local/share/ca-certificates/cert_Subordinate_CA.pem'
- '/etc/pki/ca-trust/source/anchors/cert_Root_CA.pem:/usr/local/share/ca-certificates/cert_Root_CA.pem'
- '/etc/pki/ca-trust/source/anchors/cert.pem:/usr/local/share/ca-certificates/cert.pem'
networks:
traefik:
external:
name: traefik
When I am in the container, I've got this missing rights with ?????????? :
root#2ce5b349fc30:/app# ls -ail /usr/local/share/ca-certificates/
ls: cannot access '/usr/local/share/ca-certificates/cert_Subordinate_CA.pem': Permission denied
ls: cannot access '/usr/local/share/ca-certificates/cert_Root_CA.pem': Permission denied
ls: cannot access '/usr/local/share/ca-certificates/cert.pem': Permission denied
total 0
18302330 drwxr-xr-x. 1 root root 105 Aug 1 14:24 .
890135 drwxr-xr-x. 1 root root 29 Jul 12 13:53 ..
? -?????????? ? ? ? ? ? cert_Subordinate_CA.pem
? -?????????? ? ? ? ? ? cert_Root_CA.pem
? -?????????? ? ? ? ? ? cert.pem
Do you know why this docker volume lost rights when I am inside the container ?
(I have the exact same docker-compose.yml file on another server, and the volume doesn't lose rights in it.)
When I use this volume, it works :
- '/tmp/tmp/cert_Subordinate_CA.pem:/usr/local/share/ca-certificates/cert_Subordinate_CA.pem'
- '/tmp/tmp/cert_Root_CA.pem:/usr/local/share/ca-certificates/cert_Root_CA.pem'
- '/tmp/tmp/cert.pem:/usr/local/share/ca-certificates/cert.pem'
Here is rights on both directories :
[root#svprd1148 ~]# ls -ail /tmp/tmp/
total 12
17379249 drwxr-xr-x. 2 root root 89 Jul 20 20:29 .
16777288 drwxrwxrwt. 9 root root 138 Aug 4 04:05 ..
18033843 -rw-r--r--. 1 root root 1578 Jun 17 11:41 cert_Root_CA.pem
18033827 -rw-r--r--. 1 root root 1125 Jun 17 10:20 cert_Subordinate_CA.pemm
18033836 -rw-r--r--. 1 root root 1588 Jun 17 10:19 cert.pem
and
[root#svprd1148 ~]# ls -ail /etc/pki/ca-trust/source/anchors/
total 32
45589 drwxr-xr-x. 2 root root 188 Aug 1 16:21 .
50341743 drwxr-xr-x. 4 root root 80 Jul 20 20:23 ..
51155 -rw-r--r--. 1 root root 1125 Jun 17 10:20 cert_Subordinate_CA.pem
51156 -rw-r--r--. 1 root root 1578 Jun 17 11:41 cert_Root_CA.pem
4691079 -rw-r--r--. 1 root root 1588 Jun 17 10:19 cert.pem
And I've got "permission denied" when I try to make a "chmod 777 -R /usr/local/share/ca-certificates/" inside the container
I found the solution here :
Permission denied on accessing host directory in Docker
It's necessary to add :Z at the end of each volume.
volumes:
- '/etc/pki/ca-trust/source/anchors/cert_Subordinate_CA.pem:/usr/local/share/ca-certificates/cert_Subordinate_CA.pem:Z'
- '/etc/pki/ca-trust/source/anchors/cert_Root_CA.pem:/usr/local/share/ca-certificates/cert_Root_CA.pem:Z'
- '/etc/pki/ca-trust/source/anchors/cert.pem:/usr/local/share/ca-certificates/cert.pem:Z'
works !

Docker container fails to initalize from docker-compose

I am new to Docker and in the process of learning Docker Compose, using CentOS 8 as the host system. All of these files are in the same directory and marked executable with mode 0755.
My main application is in webapp.py:
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
#app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
There is a matching requirements.txt file:
flask
redis
A Dockerfile:
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "webapp.py"]
And a docker-compose.yml file:
version: "3"
services:
web:
build: .
ports:
- "5000:5000"
stdin_open: true
tty: true
redis:
image: "redis:alpine"
However, when I run docker-compose up, it fails by exiting the web app. Compose outputs:
[root#localhost webappl]# docker-compose up
Starting webappl_redis_1 ... done
Starting webappl_web_1 ... done
Attaching to webappl_web_1, webappl_redis_1
redis_1 | 1:C 27 Dec 2021 09:03:35.861 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 27 Dec 2021 09:03:35.861 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 27 Dec 2021 09:03:35.861 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 27 Dec 2021 09:03:35.863 * monotonic clock: POSIX clock_gettime
redis_1 | 1:M 27 Dec 2021 09:03:35.864 * Running mode=standalone, port=6379.
redis_1 | 1:M 27 Dec 2021 09:03:35.864 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 27 Dec 2021 09:03:35.864 # Server initialized
redis_1 | 1:M 27 Dec 2021 09:03:35.864 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * Loading RDB produced by version 6.2.6
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * RDB age 4147 seconds
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * RDB memory usage when created 0.77 Mb
redis_1 | 1:M 27 Dec 2021 09:03:35.865 # Done loading RDB, keys loaded: 0, keys expired: 0.
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * Ready to accept connections
webappl_web_1 exited with code 0
Why does it exit?
can you trying adding following to your web: after ports:? if stdin_open doesn't work, try stdin
stdin_open: true
tty: true

Redis cluster in docker-swarm mode updated recipe

Anyone has a working recipe of Redis cluster in swarm mode? I tried everything I know and searched the internet but seems like an impossible task.
Here is what I have so far:
version: '3.4'
services:
redis-master:
image: redis
networks:
- redisdb
ports:
- 6379:6379
volumes:
- redis-master:/data
redis-slave:
image: redis
networks:
- redisdb
command: redis-server --slaveof redis-master 6379
volumes:
- redis-slave:/data
sentinel:
image: redis
networks:
- redisdb
ports:
- 26379:26379
command: >
bash -c "echo 'port 26379' > sentinel.conf &&
echo 'dir /tmp' >> sentinel.conf &&
echo 'sentinel monitor redis-master redis-master 6379 2' >> sentinel.conf &&
echo 'sentinel down-after-milliseconds redis-master 5000' >> sentinel.conf &&
echo 'sentinel parallel-syncs redis-master 1' >> sentinel.conf &&
echo 'sentinel failover-timeout redis-master 5000' >> sentinel.conf &&
cat sentinel.conf &&
redis-server sentinel.conf --sentinel"
links:
- redis-master
- redis-slave
volumes:
redis-master:
driver: local
redis-slave:
driver: local
networks:
redisdb:
attachable: true
driver: overlay
I use the following command to deploy as a service:
docker stack deploy --compose-file docker-compose-test.yml redis
The result is deployed services, were redis-master and redis-slave are connecting and I can see the synchronization processes happening as follows:
redis-master log:
1:C 16 Oct 2019 04:19:42.720 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 16 Oct 2019 04:19:42.720 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 16 Oct 2019 04:19:42.720 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 16 Oct 2019 04:19:42.723 * Running mode=standalone, port=6379.
1:M 16 Oct 2019 04:19:42.723 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 16 Oct 2019 04:19:42.723 # Server initialized
1:M 16 Oct 2019 04:19:42.723 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 16 Oct 2019 04:19:42.723 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 16 Oct 2019 04:19:42.723 * Ready to accept connections
1:M 16 Oct 2019 04:19:43.976 * Replica 10.0.27.2:6379 asks for synchronization
1:M 16 Oct 2019 04:19:43.976 * Full resync requested by replica 10.0.27.2:6379
1:M 16 Oct 2019 04:19:43.976 * Starting BGSAVE for SYNC with target: disk
1:M 16 Oct 2019 04:19:43.976 * Background saving started by pid 15
15:C 16 Oct 2019 04:19:43.982 * DB saved on disk
15:C 16 Oct 2019 04:19:43.982 * RDB: 0 MB of memory used by copy-on-write
1:M 16 Oct 2019 04:19:44.053 * Background saving terminated with success
1:M 16 Oct 2019 04:19:44.053 * Synchronization with replica 10.0.27.2:6379 succeeded
Redis-slave log:
1:C 16 Oct 2019 04:19:40.776 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 16 Oct 2019 04:19:40.776 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 16 Oct 2019 04:19:40.776 # Configuration loaded
1:S 16 Oct 2019 04:19:40.779 * Running mode=standalone, port=6379.
1:S 16 Oct 2019 04:19:40.779 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:S 16 Oct 2019 04:19:40.779 # Server initialized
1:S 16 Oct 2019 04:19:40.779 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:S 16 Oct 2019 04:19:40.779 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:S 16 Oct 2019 04:19:40.779 * Ready to accept connections
1:S 16 Oct 2019 04:19:40.779 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:40.817 # Unable to connect to MASTER: Invalid argument
1:S 16 Oct 2019 04:19:41.834 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:41.851 # Unable to connect to MASTER: Invalid argument
1:S 16 Oct 2019 04:19:42.866 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:42.942 # Unable to connect to MASTER: Invalid argument
1:S 16 Oct 2019 04:19:43.970 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:43.975 * MASTER <-> REPLICA sync started
1:S 16 Oct 2019 04:19:43.975 * Non blocking connect for SYNC fired the event.
1:S 16 Oct 2019 04:19:43.975 * Master replied to PING, replication can continue...
1:S 16 Oct 2019 04:19:43.976 * Partial resynchronization not possible (no cached master)
1:S 16 Oct 2019 04:19:43.977 * Full resync from master: 39bb36f74ef0cdefdc08a2dc8d4a86112ea69f12:0
1:S 16 Oct 2019 04:19:44.053 * MASTER <-> REPLICA sync: receiving 175 bytes from master
1:S 16 Oct 2019 04:19:44.054 * MASTER <-> REPLICA sync: Flushing old data
1:S 16 Oct 2019 04:19:44.054 * MASTER <-> REPLICA sync: Loading DB in memory
1:S 16 Oct 2019 04:19:44.054 * MASTER <-> REPLICA sync: Finished with success
Redis-sentinel log:
port 26379
port 26379
dir /tmp
dir /tmp
sentinel monitor redis-master redis-master 6379 2
sentinel monitor redis-master redis-master 6379 2
sentinel down-after-milliseconds redis-master 5000
sentinel down-after-milliseconds redis-master 5000
sentinel parallel-syncs redis-master 1
sentinel parallel-syncs redis-master 1
sentinel failover-timeout redis-master 5000
sentinel failover-timeout redis-master 5000
1:X 16 Oct 2019 04:19:49.506 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
*** FATAL CONFIG FILE ERROR ***
1:X 16 Oct 2019 04:19:49.506 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:X 16 Oct 2019 04:19:49.506 # Configuration loaded
Reading the configuration file, at line 3
>>> 'sentinel monitor redis-master redis-master 6379 2'
1:X 16 Oct 2019 04:19:49.508 * Running mode=sentinel, port=26379.
1:X 16 Oct 2019 04:19:49.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
Can't resolve master instance hostname.
1:X 16 Oct 2019 04:19:49.511 # Sentinel ID is aad9553d4999951f3b37eede5968b4aa262c07a9
1:X 16 Oct 2019 04:19:49.511 # +monitor master redis-master 10.0.27.5 6379 quorum 2
1:X 16 Oct 2019 04:19:49.512 * +slave slave 10.0.27.2:6379 10.0.27.2 6379 # redis-master 10.0.27.5 6379
1:X 16 Oct 2019 04:19:54.514 # +sdown slave 10.0.27.2:6379 10.0.27.2 6379 # redis-master 10.0.27.5 6379
So the slave-announce-ip, replica-announce-ip etc are having issues:
1- because the ips keep changing
2- Overlay networks ips are not always what they show they are
So failover dose not work and if master went down slave dont kick in!

Resources