Docker Compose Lab

hi Team ,

Can anyone of you guide on above issues ?
Thanks in advance

with best regards
Pradeep Nehe

Let me attempt this task.

Not working as of now may be need to add additional args or may be this is a technical glitch.

Sir ,

Thank you for your quick response.

Can you please bring this to notice of our trainer Mumshad to guide us ?
This is the only lab we have for beginners in Docker compose and it is not working .

It shatters my confidence in whatever I have learnt in Docker and Yaml so far.
This is so basic and minimal configurations I am not sure how can I be move forward with Docker Swarm or advanced modules !!

with best regards
Pradeep Nehe

@Ayman @Inderpreet please have a look into it.

Hi @ppnehe @Tej-Singh-Rana
Kindly check the full answer :

version: '3'

services:
   db:
     image: postgres
       POSTGRES_PASSWORD: mysecretpassword

   wordpress:
     links:
       - db
     image: wordpress:latest
     ports:
       - "8085:80"   environment:
       POSTGRES_PASSWORD: mysecretpassword

   wordpress:
     links:
       - db
     image: wordpress:latest
     ports:
       - "8085:80"
1 Like

@Ayman

Sir ,

Have you tested this and worked at your end ?
I am testing this in Kodekloud platform of docker-compose lab but did not worked in my many attempts.

  1. I used your file " as it is " and below is the output

$
$ cat docker-compose.yml
version: ‘3’

services:
db:
image: postgres
POSTGRES_PASSWORD: mysecretpassword

wordpress:
links:
- db
image: wordpress:latest
ports:
- “8085:80” environment:
POSTGRES_PASSWORD: mysecretpassword

wordpress:
links:
- db
image: wordpress:latest
ports:
- “8085:80”

$
$ docker-compose up
ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
in “./docker-compose.yml”, line 6, column 25
$
$ pwd
/root/wordpress
$


I tried fixing each and every error thrown by the terminal but it did not worked for me .
Every time you notice vi below is I have tried to fix each error I received .

I thought I was fixing errors in line 6 and line 13 in every vi command below.

I have even used YAMLLINT validator which resulted in all green but did not worked when docker-compose up was tried.

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

services:
db:
image: postgres
POSTGRES_PASSWORD: mysecretpassword

wordpress:
links:
- db
image: wordpress:latest
ports:
- “8085:80”
environment:
POSTGRES_PASSWORD: mysecretpassword

wordpress:
links:
- db
image: wordpress:latest
ports:
- “8085:80”
$
$
$ docker-compose up
ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
in “./docker-compose.yml”, line 6, column 24
$ vi docker-compose.yml
$
$
$ docker-compose up
ERROR: The Compose file ‘./docker-compose.yml’ is invalid because:
Unsupported config option for services.db: ‘POSTGRES_PASSWORD’
$
$ vi docker-compose.yml
$
$
$ docker-compose up
ERROR: The Compose file ‘./docker-compose.yml’ is invalid because:
Unsupported config option for services.db: ‘POSTGRES_PASSWORD’
$
$ vi docker-compose.yml
$
$ docker-compose up
ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
in “./docker-compose.yml”, line 6, column 24
$
$ vi docker-compose.yml
$
$
$
$ docker-compose up
ERROR: The Compose file ‘./docker-compose.yml’ is invalid because:
Unsupported config option for services.db: ‘POSTGRES_PASSWORD’
$

Dear,

“As it is” is not working.

I used below and it worked for me.

version: ‘3’

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

wordpress:
links:
- db
image: wordpress:latest
ports:
- “8085:80”

Thanks

strange

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

I am using depends_on instead of links. I don’t know why its failed at that time.

As far as the info i got from stackoverflow.

“depends-on decides the dependency and the order of container creation and links not only does these, but also containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.”

i.e., with links wordpress will be able to access the database using port exposed in the db image. If depends_on was used, this wouldn’t be possible, but the startup order of the containers would be correct.

It makes sense for the issue here.

1 Like

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