Docker Compose Lab

Thanks @farash, to point it out that issue. May be i am not looking at that point of view.

@farash ,@Ayman ,@Tej-Singh-Rana

=========================================================================

I used your latest updated file as it is but runs into error .
ERROR: In file ‘./docker-compose.yml’, service must be a mapping, not a NoneType.

$ pwd
/root/wordpress
$ ls
docker-compose.yml$ cat docker-compose.ymlversion: ‘3’

services:
db:
image: postgres
environment:

  • POSTGRES_PASSWORD=mysecretpassword

wordpress:
links:

  • db
    image: wordpress:latest
    ports:
  • “8085:80”
    $
    $ docker-compose config
    ERROR: In file ‘./docker-compose.yml’, service must be a mapping, not a NoneType.
    $
    $

================= ========================

$ cat docker-compose.yml
version: ‘3’
services:
db:
image: postgres
environment:
- POSTGRES_PASSWORD=mysecretpassword

wordpress:
links:
- db
image: wordpress:latest
ports:
- “8085:80”
$
$
$ docker-compose config
ERROR: In file ‘./docker-compose.yml’, service ‘ports’ must be a mapping not an array.

=============================================================================

I had to fix this error to change ports to direct mapping and not an array.
I did that and ran again Got another error as below

version: ‘3.3’

services: db: image: postgres
environment:
- POSTGRES_PASSWORD=mysecretpassword

wordpress:
links:
- db
image: wordpress:latest
ports: “8085:80”
$
$
$ docker-compose config
ERROR: Version in “./docker-compose.yml” is unsupported. You might be seeing this error because you’re using the wrong Compose file version. Either specify a supported version (e.g"2.2" or “3.3”) and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.For more on the Compose file format versions, see Overview | Docker Docs

==============================================

I visited this website but could not fix the errors using this guidance to make this running without errors.

=================================================

Below are the outputs of the versions I have captured of docker and platform on kodkloud lab terminal
$docker -v
Docker version 18.09.7, build 2d0083d
$

$
$ cat /etc/release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION=“Ubuntu 16.04.6 LTS”
NAME=“Ubuntu”
VERSION=“16.04.6 LTS (Xenial Xerus)”
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=“Ubuntu 16.04.6 LTS”
VERSION_ID=“16.04”
HOME_URL=“http://www.ubuntu.com/
SUPPORT_URL=“http://help.ubuntu.com/
BUG_REPORT_URL=“Bugs : Ubuntu
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$
$

I am running this in the kodekloud lab platform which is made available to users for doing lab.
Are you running these scripts in exactly same platform by launching the lab of docker-compose ?

If it works at your end can you please also include of
$docker-compose config
$docker-compose up

hi @Tej-Singh-Rana

Thanks for this . I ran this in the kodkloud lab terminal and I did not found any errors for this file .

$ cat docker-compose.yml
version: ‘3’
services:
db:
image: postgres
environment:
- POSTGRES_PASSWORD=mysecretpassword
wordpress:
image: wordpress
ports:
- ‘8085:80’
links:
- db
$
$ docker-compose config
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80/tcp
version: ‘3.0’

$
$ docker-compose up
Creating network “wordpress_default” with the default driver
Creating wordpress_db_1 …
Creating wordpress_db_1 … done
Creating wordpress_wordpress_1 …
Creating wordpress_wordpress_1 … done
Attaching to wordpress_db_1, wordpress_wordpress_1
db_1 | The files belonging to this database system will be owned by user “postgres”.
db_1 | This user must also own the server process.
db_1 |
wordpress_1 | WordPress not found in /var/www/html - copying now…
db_1 | The database cluster will be initialized with locale “en_US.utf8”.
db_1 | The default database encoding has accordingly been set to “UTF8”.
db_1 | The default text search configuration will be set to “english”.
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /var/lib/postgresql/data … ok
db_1 | creating subdirectories … ok
db_1 | selecting dynamic shared memory implementation … posix
db_1 | selecting default max_connections … 100
db_1 | selecting default shared_buffers … 128MB
db_1 | selecting default time zone … Etc/UTC
db_1 | creating configuration files … ok
db_1 | running bootstrap script … ok
db_1 | performing post-bootstrap initialization … ok
db_1 | syncing data to disk … ok
db_1 |
db_1 | initdb: warning: enabling “trust” authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 | waiting for server to start…2020-05-30 08:22:53.465 UTC [45] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-05-30 08:22:53.466 UTC [45] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2020-05-30 08:22:53.488 UTC [46] LOG: database system was shut down at 2020-05-30 08:22:53 UTC
db_1 | 2020-05-30 08:22:53.492 UTC [45] LOG: database system is ready to accept connections
wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html
db_1 | done
db_1 | server started
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | 2020-05-30 08:22:53.552 UTC [45] LOG: received fast shutdown request
db_1 | waiting for server to shut down…2020-05-30 08:22:53.555 UTC [45] LOG: aborting any active transactions
db_1 | 2020-05-30 08:22:53.557 UTC [45] LOG: background worker “logical replication launcher” (PID 52) exited with exit code 1
db_1 | 2020-05-30 08:22:53.561 UTC [47] LOG: shutting down
db_1 | 2020-05-30 08:22:53.570 UTC [45] LOG: database system is shut down
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.19.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.19.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | [Sat May 30 08:22:53.648768 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.18 configured – resuming normal operations
wordpress_1 | [Sat May 30 08:22:53.648825 2020] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2020-05-30 08:22:53.664 UTC [1] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-05-30 08:22:53.664 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2020-05-30 08:22:53.665 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2020-05-30 08:22:53.667 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2020-05-30 08:22:53.684 UTC [54] LOG: database system was shut down at 2020-05-30 08:22:53 UTC
db_1 | 2020-05-30 08:22:53.690 UTC [1] LOG: database system is ready to accept connections

hi @Tej-Singh-Rana

I have reversed the order now of your file and tried again i.e. putting wordpress before db in this Yaml file and still it worked .
May because link- takes care to launch the dependancies first before launching wordpress.
There is no issue now.

Only thing I would need to know or find out is what could be summary of learnings or takeaway from all these iterations.

$ pwd
/root/wordpress
$ ls
docker-compose.yml
$ cat docker-compose.yml

version: ‘3’
services:
wordpress:
image: wordpress
ports:
- ‘8085:80’
links:
- db
db:
image: postgres
environment:
- POSTGRES_PASSWORD=mysecretpassword
$
$ docker-compose config
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80/tcp
version: ‘3.0’

$
$
$ docker-compose up
Starting wordpress_db_1 …
Starting wordpress_db_1 … done
Starting wordpress_wordpress_1 …
Starting wordpress_wordpress_1 … done
Attaching to wordpress_db_1, wordpress_wordpress_1
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-05-30 08:56:47.944 UTC [1] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-05-30 08:56:47.945 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2020-05-30 08:56:47.945 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2020-05-30 08:56:47.947 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2020-05-30 08:56:47.968 UTC [25] LOG: database system was shut down at 2020-05-30 08:54:34 UTC
db_1 | 2020-05-30 08:56:47.976 UTC [1] LOG: database system is ready to accept connections
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.19.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.19.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | [Sat May 30 08:56:48.617058 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.18 configured – resuming normal operations
wordpress_1 | [Sat May 30 08:56:48.617170 2020] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’

Indentation error, You are doing syntax error that’s why it’s throwing errors.

@ppnehe @farash @Tej-Singh-Rana
Kindly check the correct code below as I recheck it :

services:
 db:
   environment:
     POSTGRES_PASSWORD: mysecretpassword
   image: postgres
 wordpress:
   image: wordpress
   links:
   - db
   ports:
   - 8085:80
version: '3.0'

Also, check my try below:
check_wordpress

Sometimes the correct answer is located under path /var/answers/ as you can find the above answer inside it.

We do sorry for any inconvenience.

I hope this helps!

Thank you Sir @Ayman

I have verified this yml code and this one works absolutely fine without any issues.
This passes all of the verification checks scripted at the end of the docker-compose lab

Also thank you for the hint on to verify right answers under /var

with best regards
Pradeep Nehe

$ pwd
/root/wordpress
$
$ cat docker-compose.yml
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80
version: ‘3.0’
$
$ docker-compose config
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80/tcp
version: ‘3.0’

$
$ docker-compose up
Creating network “wordpress_default” with the default driver
Creating wordpress_db_1 …
Creating wordpress_db_1 … done
Creating wordpress_wordpress_1 …
Creating wordpress_wordpress_1 … done
Attaching to wordpress_db_1, wordpress_wordpress_1
db_1 | The files belonging to this database system will be owned by user “postgres”.
db_1 | This user must also own the server process.
db_1 |
db_1 | The database cluster will be initialized with locale “en_US.utf8”.
db_1 | The default database encoding has accordingly been set to “UTF8”.
db_1 | The default text search configuration will be set to “english”.
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /var/lib/postgresql/data … ok
db_1 | creating subdirectories … ok
db_1 | selecting dynamic shared memory implementation … posix
db_1 | selecting default max_connections … 100
db_1 | selecting default shared_buffers … 128MB
db_1 | selecting default time zone … Etc/UTC
db_1 | creating configuration files … ok
db_1 | running bootstrap script … ok
db_1 | performing post-bootstrap initialization … ok
wordpress_1 | WordPress not found in /var/www/html - copying now…
db_1 | syncing data to disk … ok
db_1 |
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 | initdb: warning: enabling “trust” authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 | waiting for server to start…2020-06-04 10:14:19.845 UTC [45] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-06-04 10:14:19.846 UTC [45] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2020-06-04 10:14:19.859 UTC [46] LOG: database system was shut down at 2020-06-04 10:14:19 UTC
db_1 | 2020-06-04 10:14:19.865 UTC [45] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | 2020-06-04 10:14:19.937 UTC [45] LOG: received fast shutdown request
wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html
db_1 | waiting for server to shut down…2020-06-04 10:14:19.941 UTC [45] LOG: aborting any active transactions
db_1 | 2020-06-04 10:14:19.942 UTC [45] LOG: background worker “logical replication launcher” (PID 52) exited with exit code 1
db_1 | 2020-06-04 10:14:19.945 UTC [47] LOG: shutting down
db_1 | 2020-06-04 10:14:19.955 UTC [45] LOG: database system is shut down
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.19.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.19.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | [Thu Jun 04 10:14:20.039469 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.18 configured – resuming normal operations
wordpress_1 | [Thu Jun 04 10:14:20.039515 2020] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2020-06-04 10:14:20.056 UTC [1] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-06-04 10:14:20.057 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2020-06-04 10:14:20.057 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2020-06-04 10:14:20.059 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2020-06-04 10:14:20.073 UTC [54] LOG: database system was shut down at 2020-06-04 10:14:19 UTC
db_1 | 2020-06-04 10:14:20.077 UTC [1] LOG: database system is ready to accept connections

Hi @goel.umang7

Please check the response from @Ayman on same thread.
This script worked for us and it passes all checks scripted at the verification stages of this lab.

===============================================================

$ cat docker-compose.yml
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80
version: ‘3.0’
$

=============================================================

1 Like

Thanks Everyone for helping out in this issue.

1 Like

Hi everyone,

I’m facing the same issue , and apparently, is the same solution that was provided by @Ayman:

docker-compose

Any help is welcome, thanks

hi @el-jose and @Ayman

I just ran this again and I am too exactly getting same FAIL checks in verification stages.
I am not able to see any errors . I have attached below outputs to help us improve our troubleshooting skills.

Based on docker network ls , docker network inspect and docker container inspect commands it appears that both the containers are in same network 172.19.0.0/16

Can you please guide us based on below output

What more troubleshooting commands and steps we need to take ?
Where else to look for the errors ?

As I am using file same as from /var/asnwers/answers.txt I am assuming there are no changes made to that file when it ran last time successfully couple of weeks ago.

$ pwd
/root/wordpress
$
$ ls -al
total 12
drwxr-xr-x 2 root root 4096 Jun 13 00:53 .
drwx------ 5 root root 4096 Jun 13 00:53 …
-rw-r–r-- 1 root root 189 Jun 13 00:53 docker-compose.yml
$
$
$ cat docker-compose.yml
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80
version: ‘3.0’
$
$ docker-compose config
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
wordpress:
image: wordpress
links:
- db
ports:
- 8085:80/tcp
version: ‘3.0’

$
$
$ docker-compose up -d
Creating wordpress_db_1 …
Creating wordpress_db_1 … done
Creating wordpress_wordpress_1 …
Creating wordpress_wordpress_1 … done
$
$
$
$
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e62d05a2818e wordpress “docker-entrypoint.s…” 28 seconds ago Up 27 seconds 0.0.0.0:8085->80/tcp wordpress_wordpress_1
2a1038f5740e postgres “docker-entrypoint.s…” 29 seconds ago Up 27 seconds 5432/tcp wordpress_db_1
$
$
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
88e4e1c90c31 bridge bridge local
25818271944e host host local
fe6f1f6a903a none null local
0fa4d0a856d3 wordpress_default bridge local
$
$
$ docker network inspect 0f
[
{
“Name”: “wordpress_default”,
“Id”: “0fa4d0a856d33b2394cd9687af548bed791c649ccdb1e6eb67cfef253d297138”,
“Created”: “2020-06-13T00:53:48.157901239Z”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: [
{
“Subnet”: “172.19.0.0/16”,
“Gateway”: “172.19.0.1”
}
]
},
“Internal”: false,
“Attachable”: true,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42”: {
“Name”: “wordpress_db_1”,
“EndpointID”: “7a0eacde45d8ddf8c919790039d42878984c427305f98bb1d0e43bcb55e38048”,
“MacAddress”: “02:42:ac:13:00:02”,
“IPv4Address”: “172.19.0.2/16”,
“IPv6Address”: “”
},
“e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6”: {
“Name”: “wordpress_wordpress_1”,
“EndpointID”: “39d352a6177a0d5b3d15cc8abc2c8f802ce8baa3ca1704d10e5aad7a777cc2f9”,
“MacAddress”: “02:42:ac:13:00:03”,
“IPv4Address”: “172.19.0.3/16”,
“IPv6Address”: “”
}
},
“Options”: {},
“Labels”: {
“com.docker.compose.network”: “default”,
“com.docker.compose.project”: “wordpress”
}
}
]
$
$
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e62d05a2818e wordpress “docker-entrypoint.s…” 59 seconds ago Up 58 seconds 0.0.0.0:8085->80/tcp wordpress_wordpress_1
2a1038f5740e postgres “docker-entrypoint.s…” About a minute ago Up 59 seconds 5432/tcp wordpress_db_1
$
$ docker container inspect e62
[
{
“Id”: “e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6”,
“Created”: “2020-06-13T01:23:24.560492734Z”,
“Path”: “docker-entrypoint.sh”,
“Args”: [
“apache2-foreground”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 6244,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2020-06-13T01:23:25.146366232Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:2c9350d16623803c9bcfa58973b9bdba18e06d3107b15ba8090c09db946c27bf”,
“ResolvConfPath”: “/var/lib/docker/containers/e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6/hostname”,
“HostsPath”: “/var/lib/docker/containers/e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6/hosts”,
“LogPath”: “/var/lib/docker/containers/e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6/e62d05a2818ea0962042ab4e1f00a17f1e79b6ffeef324a945af476f8c0b71f6-json.log”,
“Name”: “/wordpress_wordpress_1”,
“RestartCount”: 0,
“Driver”: “overlay”,
“Platform”: “linux”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “docker-default”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: [],
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “wordpress_default”,
“PortBindings”: {
“80/tcp”: [
{
“HostIp”: “”,
“HostPort”: “8085”
}
]
},
“RestartPolicy”: {
“Name”: “”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: [],
“CapAdd”: null,
“CapDrop”: null,
“Dns”: null,
“DnsOptions”: null,
“DnsSearch”: null,
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “shareable”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: null,
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: null,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0,
“MaskedPaths”: [
“/proc/asound”,
“/proc/acpi”,
“/proc/kcore”,
“/proc/keys”,
“/proc/latency_stats”,
“/proc/timer_list”,
“/proc/timer_stats”,
“/proc/sched_debug”,
“/proc/scsi”,
“/sys/firmware”
],
“ReadonlyPaths”: [
“/proc/bus”,
“/proc/fs”,
“/proc/irq”,
“/proc/sys”,
“/proc/sysrq-trigger”
]
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay/94005bd4b5e89b71c6fc96092d5202106afbab95304919c36ec566cd4db0e802/root”,
“MergedDir”: “/var/lib/docker/overlay/53ba1589093f9c06b3f92aa984887beba5cafe89062a18520f3e490ca03f1e70/merged”,
“UpperDir”: “/var/lib/docker/overlay/53ba1589093f9c06b3f92aa984887beba5cafe89062a18520f3e490ca03f1e70/upper”,
“WorkDir”: “/var/lib/docker/overlay/53ba1589093f9c06b3f92aa984887beba5cafe89062a18520f3e490ca03f1e70/work”
},
“Name”: “overlay”
},
“Mounts”: [
{
“Type”: “volume”,
“Name”: “c709901c6561c3d7fc2794283be93e713b104fd3c63d86de700135a78daeff63”,
“Source”: “/var/lib/docker/volumes/c709901c6561c3d7fc2794283be93e713b104fd3c63d86de700135a78daeff63/_data”,
“Destination”: “/var/www/html”,
“Driver”: “local”,
“Mode”: “”,
“RW”: true,
“Propagation”: “”
}
],
“Config”: {
“Hostname”: “e62d05a2818e”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“80/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c”,
“PHP_INI_DIR=/usr/local/etc/php”,
“APACHE_CONFDIR=/etc/apache2”,
“APACHE_ENVVARS=/etc/apache2/envvars”,
“PHP_EXTRA_BUILD_DEPS=apache2-dev”,
“PHP_EXTRA_CONFIGURE_ARGS=–with-apxs2 --disable-cgi”,
“PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64”,
“PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64”,
“PHP_LDFLAGS=-Wl,-O1 -pie”,
“GPG_KEYS=CBAF69F173A0FEA4B537F470D66C9593118BCCB6 F38252826ACD957EF380D39F2F7956BC5DA04B5D”,
“PHP_VERSION=7.3.19”,
“PHP_URL=https://www.php.net/distributions/php-7.3.19.tar.xz”,
“PHP_ASC_URL=https://www.php.net/distributions/php-7.3.19.tar.xz.asc”,
“PHP_SHA256=6402faa19b1a8c4317c7612632bce985684a5bbae0980a5779a4019439882422”,
“PHP_MD5=”,
“WORDPRESS_VERSION=5.4.2”,
“WORDPRESS_SHA1=e5631f812232fbd45d3431783d3db2e0d5670d2d”
],
“Cmd”: [
“apache2-foreground”
],
“ArgsEscaped”: true,
“Image”: “wordpress”,
“Volumes”: {
“/var/www/html”: {}
},
“WorkingDir”: “/var/www/html”,
“Entrypoint”: [
“docker-entrypoint.sh”
],
“OnBuild”: null,
“Labels”: {
“com.docker.compose.config-hash”: “3c6abed06257bbfc34b5e3d5522d06897757e91a2d2016da717b8ea8dbdd1c85”,
“com.docker.compose.container-number”: “1”,
“com.docker.compose.oneoff”: “False”,
“com.docker.compose.project”: “wordpress”,
“com.docker.compose.service”: “wordpress”,
“com.docker.compose.version”: “1.16.1”
},
“StopSignal”: “SIGWINCH”
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “132c5c9b18158359cd2e9c848b819cbae4c87916c1216d026036d3a3fb834544”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“80/tcp”: [
{
“HostIp”: “0.0.0.0”,
“HostPort”: “8085”
}
]
},
“SandboxKey”: “/var/run/docker/netns/132c5c9b1815”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “”,
“Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “”,
“IPPrefixLen”: 0,
“IPv6Gateway”: “”,
“MacAddress”: “”,
“Networks”: {
“wordpress_default”: {
“IPAMConfig”: null,
“Links”: [
“wordpress_db_1:db”,
“wordpress_db_1:db_1”,
“wordpress_db_1:wordpress_db_1”
],
“Aliases”: [
“wordpress”,
“e62d05a2818e”
],
“NetworkID”: “0fa4d0a856d33b2394cd9687af548bed791c649ccdb1e6eb67cfef253d297138”,
“EndpointID”: “39d352a6177a0d5b3d15cc8abc2c8f802ce8baa3ca1704d10e5aad7a777cc2f9”,
“Gateway”: “172.19.0.1”,
“IPAddress”: “172.19.0.3”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:13:00:03”,
“DriverOpts”: null
}
}
}
}
]
$
$ docker container inspect 2a1
[
{
“Id”: “2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42”,
“Created”: “2020-06-13T01:23:23.951818347Z”,
“Path”: “docker-entrypoint.sh”,
“Args”: [
“postgres”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 6077,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2020-06-13T01:23:24.512991739Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:b97bae343e06e050f84c781eee8a9d6b0688b8bbdcc0161990573c194b333479”,
“ResolvConfPath”: “/var/lib/docker/containers/2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42/hostname”,
“HostsPath”: “/var/lib/docker/containers/2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42/hosts”,
“LogPath”: “/var/lib/docker/containers/2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42/2a1038f5740ea1a116adbb3d2e2bbd229e5083c879833f4373bbd4606073bc42-json.log”,
“Name”: “/wordpress_db_1”,
“RestartCount”: 0,
“Driver”: “overlay”,
“Platform”: “linux”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “docker-default”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: [],
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “wordpress_default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: [],
“CapAdd”: null,
“CapDrop”: null,
“Dns”: null,
“DnsOptions”: null,
“DnsSearch”: null,
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “shareable”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: null,
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: null,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0,
“MaskedPaths”: [
“/proc/asound”,
“/proc/acpi”,
“/proc/kcore”,
“/proc/keys”,
“/proc/latency_stats”,
“/proc/timer_list”,
“/proc/timer_stats”,
“/proc/sched_debug”,
“/proc/scsi”,
“/sys/firmware”
],
“ReadonlyPaths”: [
“/proc/bus”,
“/proc/fs”,
“/proc/irq”,
“/proc/sys”,
“/proc/sysrq-trigger”
]
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay/b2a34bfa6639c266d52d2fb21bde48339ba009a5cf87e3a47295b4db1f4a11f7/root”,
“MergedDir”: “/var/lib/docker/overlay/1c6fe784a79e70218fc7f5bec4b6ca510ad223e0f38d873c100df789e14af457/merged”,
“UpperDir”: “/var/lib/docker/overlay/1c6fe784a79e70218fc7f5bec4b6ca510ad223e0f38d873c100df789e14af457/upper”,
“WorkDir”: “/var/lib/docker/overlay/1c6fe784a79e70218fc7f5bec4b6ca510ad223e0f38d873c100df789e14af457/work”
},
“Name”: “overlay”
},
“Mounts”: [
{
“Type”: “volume”,
“Name”: “242de1cf2af3b2d9bbf4f7f8954ec61198900fc0fff54613719098b9ab56d458”,
“Source”: “/var/lib/docker/volumes/242de1cf2af3b2d9bbf4f7f8954ec61198900fc0fff54613719098b9ab56d458/_data”,
“Destination”: “/var/lib/postgresql/data”,
“Driver”: “local”,
“Mode”: “”,
“RW”: true,
“Propagation”: “”
}
],
“Config”: {
“Hostname”: “2a1038f5740e”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“5432/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“POSTGRES_PASSWORD=mysecretpassword”,
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/12/bin”,
“GOSU_VERSION=1.12”,
“LANG=en_US.utf8”,
“PG_MAJOR=12”,
“PG_VERSION=12.3-1.pgdg100+1”,
“PGDATA=/var/lib/postgresql/data”
],
“Cmd”: [
“postgres”
],
“ArgsEscaped”: true,
“Image”: “postgres”,
“Volumes”: {
“/var/lib/postgresql/data”: {}
},
“WorkingDir”: “”,
“Entrypoint”: [
“docker-entrypoint.sh”
],
“OnBuild”: null,
“Labels”: {
“com.docker.compose.config-hash”: “4f299f4dcdd14d3f6993f758213d49dbcd0a367ec89c0b24ef4168e4385f246f”,
“com.docker.compose.container-number”: “1”,
“com.docker.compose.oneoff”: “False”,
“com.docker.compose.project”: “wordpress”,
“com.docker.compose.service”: “db”,
“com.docker.compose.version”: “1.16.1”
}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “4add2ea48402b562649261bfd00e14e80ffeb78fa1ee44fdff6331afe8db7aa9”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“5432/tcp”: null
},
“SandboxKey”: “/var/run/docker/netns/4add2ea48402”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “”,
“Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “”,
“IPPrefixLen”: 0,
“IPv6Gateway”: “”,
“MacAddress”: “”,
“Networks”: {
“wordpress_default”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: [
“2a1038f5740e”,
“db”
],
“NetworkID”: “0fa4d0a856d33b2394cd9687af548bed791c649ccdb1e6eb67cfef253d297138”,
“EndpointID”: “7a0eacde45d8ddf8c919790039d42878984c427305f98bb1d0e43bcb55e38048”,
“Gateway”: “172.19.0.1”,
“IPAddress”: “172.19.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:13:00:02”,
“DriverOpts”: null
}
}
}
}
]
$
$

Linking problem is still coming


We will fix it and keep you updated ASAP.

Hi @Ayman

Thanks for your quick reply and stepping in to provide the fix.

It would profit more to guide us how can we students can approach a problems like this on our own and what next steps we can take to improve troubleshooting and debugging skills to next level.

ex

  1. How many more troubleshooting commands we can use to fix similar situation ?

docker container ls
docker network ls
docker network inspect network_id
docker container inspect container_id
docker-compose config

Is there anything like systemctl / journal log file inspection possible in these containers ? Hpw to use those commands

  1. What are the other areas to look for ?
    ex
    whether both the containers are in same network or no by inspecting their IP address
    whether both the containers have same default gateway as it appears to be correct
    whether link is defined in yaml code which appears as present
    whether link is really established once containers are created and why

  2. Is there any authentication issue between the two containers . How to find it ?

  3. How to take forward debugging to next level.

Your guidance will help us more than the fix in our own realtime environment and docker learning journey.

with best regards
Pradeep Nehe

In last tab (05) there is no detailed description about specs for containers. Please add them.

My Docker-compose.yml file:
version: “3”
services:
wordpress:
image: wordpress
ports:
- 8085:80
links:
- “db”
db:
image: postgres
environment:
- POSTGRES_PASSWORD=“mysecretpassword”

All checks passed except: WordPress linked to db container
In Version 3 of Docker Compose we do not need links at all as far as I know but I have added it explicitly. Docker-compose up works, but cannot connect to database during wordpress setup
I used following:
database: wordpress
user: postgres
password: mysecretpassword
host: db

Any idea ?

Hi @andrzej

Do you mean output needed of
docker container inspect container_ID from both the containers in addition to above ?

with best regards
Pradeep Nehe

Sorry did not get what do you mean.

hi @mmumshad / @Ayman

This lab had issues initially and you helped by providing updated yml code file.
For couple of weeks this lab of docker-compose started working fine .

Today it is failing again and I am of the impression the file which I am using today is same which was able to pass all of these task under docker-compose lab.

I am able to see both the containers wordpress and db are launched under a dedicated network “wordpress_default” in same network id but the CHECKS fail .

It appears this is not a issue with yml syntax but seems link function is not working.

Can you please add one module in docker troubleshooting section which will help all of us how to take forward our debugging skills .

Also can you please guide what more troubleshooting I could have done or can still do to resolve this error.

Thanks in advance.docker compose - lab fail.pdf (104.0 KB)

with best regards
Pradeep Nehe

2 Likes

Hi All,
I have managed to resolve the issue. The lab check is incorrectly built. Even after I was being able to connect to the postgres db from the wordpress site, the question check boxes were still showing that the link with the db was not established.

So, first things first. It might be very frustrating to know that postgres is not a supported db for wordpress. However, there are workarounds to configure the wordpress application to connect to the postgres db. I spent not hours but quite a few days to figure the whole solution out.

The following areas need your attention:

1) Wordpress:

A) The wordpress image (wordpress:latest) is being used in this case. While the wordpress container is running, the entire wordpress content is located under /var/www/html/ within the container.

B) The wp-config.php file under /var/www/html is the configuration file which will need to be modified with the “name of the db (DB_NAME)”, “password for the db (DB_PASSWORD)”, “user of the db (DB_USER)” and “db hostname or IP address along with port details (DB_HOST)”.
For example, I used: DB_NAME=postgres, DB_PASSWORD=postgres, DB_USER=postgres. All of these are default postgres db elements. If you want to change them then you will have to go into the postgres db container and create a new database and specific users and generate passwords for it. Then you will have to come back to the wp-config.php file to update that. The DB_HOST=<the ip address found within the db container after using “cat /etc/hosts” followed by :5432>. So it looks like DB_HOST=:

C) Wordpress is developed in python. However, there was no driver developed for Wordpress to connect to the db. There is a wordaround to this though. There is a special plugin enabling Wordpress to be used with a PostgreSQL database has been developed by kevinoid. This can be found in the below link:

The above github link will need to be cloned into the running Wordpress container under folder /var/www/html/wp-content. The folder “PG4WP” under “postgresql-for-wordpress” directory will need to be copied directly under /var/www/html/wp-content/. The file “db.php” under “PG4WP”
will also need to be copied under /var/www/html/wp-content.

D) Additionally, there are some python libraries or extensions for PostgreSQL which will also need to be downloaded and installed within the Wordpress container. These are as follows:

libpq-dev
pdo
pdo_pgsql
pgsql

2) PostgreSQL DB:

PostgreSQL container will be deployed as usual with the password environment variable POSTGRES_PASSWORD=postgres with the help of docker-compose command.

3) Finally, a WordPress image will need to be created with the additional details above and then docker-compose will be used to deploy it.

A) I am adding my Dockerfile details which I used to create the new Wordpress image which was then used to deploy the Wordpress container.

Dockerfile:

FROM wordpress:latest
# Updating container, installing git, installing vim (editor), installing libpq-dev, pdo, pdo_pgsql, pgsql extentions. (This line can be removed)
RUN apt-get update \
&& apt-get install git -y \
&& apt-get install vim -y \
&& apt-get install libpq-dev -y \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
# Creating a directory under /home called wp and git cloning kevinoid’s wordpress plugin for postgress. (This line can be removed)
RUN mkdir /home/wp \
&& cd /home/wp \
&& git clone GitHub - kevinoid/postgresql-for-wordpress: A temporary fork of https://wordpress.org/plugins/postgresql-for-wordpress/ with changes from kevinoid. \

================================================================================================================================================

B) The docker image will be built with the following command run from the same directory where the Dockerfile is located:

docker build . -t wordpress:new

C) After the image is created the following docker-compose will need to be deployed to run the containers. The following is my docker-compose.yml file.

docker-compose.yml

version: “3.3”
services:
db:
image: postgres
container_name: db
networks:
- app-network
environment:
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
wordpress:
image: wordpress:new
container_name: wordpress
networks:
- app-network
ports:
- 8085:80
links:
- db
networks:
app-network:
driver: bridge

D) Once both postgres db and wordpress containers are up and running then use the following commands to log on to the wordpress container.

docker ps #To note the container ids.

docker exec -it (wordpress container id) bash

cp postgresql-for-wordpress/pg4wp /var/www/html/wp-content/pg4wp -r #copy pg4wp to wp-content folder.

cp /var/www/html/wp-content/pg4wp/db.php /var/www/html/wp-content/db.php #copy pg4wp/db.php to wp-content folder. I tried to copy this while building the image but then I realised that when I run the container with docker-compose.yml the wp-content folder is overwritten by apache2 with a new set of wordpress files. I am not sure why. So, I thought of doing this after the container was running.

vi /var/www/html/wp-config.php # Here edit the DB_HOST, DB_USER, DB_PASSWORD & DB_NAME with the following values:

DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=postgres

DB_HOST=(as discussed earlier this will need to be obtained by connecting to db running container the same way wordpress is connected. E.g. docker exec -it (db container id) bash. Then by running command : cat /etc/hosts.). This will be followed by port number 5432.

Save the file and exit out of the wordpress container.

Once done, you will be able to access the wordpress site and it will be able to connect to the database.

This however, will still not allow the KodeKloud quiz to check the connectivity of the db from wordpress container and acknowledge that.

Hope this helps. Thanks for reading.

PS: This post does not maintain the indent of the Dockerfile or the docker-compose.yml. This will need to be checked seperately.