Docker Compose Lab

My docker-compose file is running but the check button on quiz says that it is not correct. Can someone please review and tell whats the problem here.

wordpress:
image: wordpress
ports:
- 8085:80
links:
- db
volumes:
- ./root/wordpress
db:
image: postgres
environment:
POSTGRES_PASSWORD: mysecretpassword

wordpress:
image: wordpress
ports:
- 8085:80
links:
- db
volumes:
- ./root/wordpress
db:
image: postgres
environment:
- POSTGRES_PASSWORD: mysecretpassword
1 Like

Sir , This is not working at my lab terminal . I just tried and attaching all output . Can you please help me understand my errors.

$ docker-compose config
services:
db:
environment:
POSTGRES_PASSWORD: mysecretpassword
image: postgres
network_mode: bridge
wordpress:
image: wordpress
links:
- db
network_mode: bridge
ports:
- 8085:80/tcp
volumes:
- root/wordpress
version: ‘2.1’

docker-compose up docker-compose.yml
ERROR: No such service: docker-compose.yml
pwd
/root/workdpress
$ tree
.
└── docker-compose.yml

0 directories, 1 file
ls -al total 12 drwxr-xr-x 2 root root 4096 May 13 21:46 . drwx------ 5 root root 4096 May 13 21:46 .. -rw-r--r-- 1 root root 176 May 13 21:46 docker-compose.yml

version: "2.1"
services:
 db:
   environment: 
    - POSTGRES_PASSWORD: mysecretpassword
   image: postgres
   network_mode: bridge
 wordpress:
   image: wordpress
   links:
   - db
   network_mode: bridge
   ports:
    - "8085:80"
   volumes:
   - ./root/wordpress

Thank you Sir , player001

I tried this and got few errors at my terminal .
I tried fixing them but still ran into other errors . Attached is below output

with best regards
Pradeep Nehe

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

mkdir wordpress cd wordpress/
ls -al total 8 drwxr-xr-x 2 root root 4096 May 14 08:16 . drwx------ 5 root root 4096 May 14 08:16 ..
cat > docker-compose.yml
version: “2.1”
services:
db:
environment:
- POSTGRES_PASSWORD: mysecretpassword
image: postgres
network_mode: bridge
wordpress:
image: wordpress
links:

  • db
    network_mode: bridge
    ports:
    - “8085:80”
    volumes:
  • ./root/wordpress
    ^C
    cat docker-compose.yml
    version: “2.1”
    services:
    db:
    environment:
    - POSTGRES_PASSWORD: mysecretpassword
    image: postgres
    network_mode: bridge
    wordpress:
    image: wordpress
    links:
  • db
    network_mode: bridge
    ports:
    - “8085:80”
    volumes:
  • ./root/wordpress

    docker-compose config ERROR: The Compose file './docker-compose.yml' is invalid because: services.db.environment contains {"POSTGRES_PASSWORD": "mysecretpassword"}, which is an invalid type, it should be a string
    docker-compose up docker-compose.yml ERROR: The Compose file './docker-compose.yml' is invalid because: services.db.environment contains {"POSTGRES_PASSWORD": "mysecretpassword"}, which is an invalid type, it should be a string

    vim docker-compose.yml
    vim docker-compose.yml
    $ docker-compose config
    services:
    db:
    environment:
    POSTGRES_PASSWORD:mysecretpassword: null
    image: postgres
    network_mode: bridge
    wordpress:
    image: wordpress
    links:
    - db
    network_mode: bridge
    ports:
    - 8085:80/tcp
    volumes:
    - root/wordpress
    version: ‘2.1’

docker-compose up docker-compose.yml
ERROR: No such service: docker-compose.yml
pwd /root/wordpress ls -al
total 12
drwxr-xr-x 2 root root 4096 May 14 08:19 .
drwx------ 5 root root 4096 May 14 08:19 …
-rw-r–r-- 1 root root 265 May 14 08:19 docker-compose.yml
vim docker-compose.yml
docker-compose up docker-compose.yml
ERROR: No such service: docker-compose.yml
cat docker-compose.yml
version: “2.1”
services:
db:
environment:
- “POSTGRES_PASSWORD:mysecretpassword”. # Adding quotes to see whether this can fix
image: postgres
network_mode: bridge
wordpress:
image: wordpress
links:

  • db
    network_mode: bridge
    ports:
    - “8085:80”
    volumes:
  • ./root/wordpress

    pwd /root/wordpress
    $ tree
    .
    └── docker-compose.yml

0 directories, 1 file
ls -al
total 12
drwxr-xr-x 2 root root 4096 May 14 08:20 .
drwx------ 5 root root 4096 May 14 08:20 …
-rw-r–r-- 1 root root 267 May 14 08:20 docker-compose.yml
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest fd5f88e17621 7 days ago 541MB
postgres latest 0f10374e5170 2 weeks ago 314MB
alpine latest 961769676411 8 months ago 5.58MB
ubuntu latest a2a15febcdf3 9 months ago 64.2MB
redis latest f7302e4ab3a8 9 months ago 98.2MB
weaveworks/scope 1.11.4 a082d48f0b39 9 months ago 78.5MB
quay.io/ansible/molecule 2.20 1171569d6ba4 14 months ago 704MB
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

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

I went to this site to put the last modified code above . This sites says this is valid YAML file .

http://www.yamllint.com/

can i knew what is the actual task is ?
in Docker-compose we don’t need to describe network because it creates automatically default network for those services. If in task it is described to create a new network then you can create.

version: "2.1"
services:
  db:
    environment:
      - POSTGRES_DB = "db"
      - POSTGRES_PASSWORD = ""
      - POSTGRES_HOST_AUTH_METHOD = "trust"
  image: postgres
  restart: always
  ports:
    - "5432:5432"
  volumes:
    - /opt/database:/var/lib/postgresql/data

  wordpress:
    image: wordpress
    links:
      - db
    ports:
      - "8085:80"
    volumes:
      - ./root/wordpress
    restart: always

facing issue in database, password authentication so kindly solve it and let me know also.

This is described in

Docker for beginners course
Module : Docker Compose Lab 4

Lab 1
First create a postgress database container called db , image postgres , environmental variable POSTGRES_PASSWORD=mysecretpassword

Lab 2
Next let’s create a simple wordpress container called wordpress , image: wordpress , link it to the container db and expose it on host port 8085

Lab 3
Now that we have a working wordpress site, lets run it with Docker Compose!
Let’s clean up the actions carried out in previous steps. Delete the db and wordpress containers.

Lab 4
Create a docker-compose.yml file under the path /root/wordpress . Once done, run a docker-compose up.
The compose file should have exact specification of the wordpress and db container

All of below checks fails and hence I have uploaded by script in above outputs.Though my script passes through yamllint.com website checks

  • Syntax Check for the docker-compose.yml
  • Wordpress running on the correct HostPort?
  • WordPress linked to db container
  • db container running with env variable POSTGRES_PASSWORD?

services:
db:
container_name: db_container
environment:
- “POSTGRES_DB = “db””
- “POSTGRES_PASSWORD = “””
- “POSTGRES_HOST_AUTH_METHOD = “trust””
image: postgres
ports:
- “5432:5432”
restart: always
wordpress:
container_name: wordpress_container
image: wordpress
links:
- db
ports:
- “8085:80”
restart: always
version: “2.1”

after this do
docker logs db_container
and try to resolve that logs.

Thank you Sir ,

I used this script and tried resolving as much as I could to reach a point where docker-compose config command does not throw any more errors .

Few things in scripts provided docker-config did not accepted while parsing such as " " given to port numbers , version number 2.2 , array for links and ports . Only after removing those script was not accepted by docker-compose config for any errors.

Now docker-compose config does not gives any error for this modified script

But docker-compose up docker-compose.yml still gives error as No such service : docker-compose.yml

I have provided all outputs below such as error logs , pwd , ls -al etc

pwd /root/wordpress
ls -al total 12 drwxr-xr-x 2 root root 4096 May 15 17:28 . drwx------ 5 root root 4096 May 15 17:28 .. -rw-r--r-- 1 root root 410 May 15 17:28 docker-compose.yml
$ docker-compose config
services:
db:
container_name: db_container
environment:
"\u201CPOSTGRES_DB “: " \u201Cdb\u201D”
"\u201CPOSTGRES_HOST_AUTH_METHOD “: " \u201Ctrust\u201D”
"\u201CPOSTGRES_PASSWORD ": ’ “mysecretpassword”’
image: postgres
ports:
- 5432:5432/tcp
restart: always
wordpress:
container_name: wordpress_container
image: wordpress
links:
- db
ports:
- 8085:80/tcp
restart: always
version: ‘3.0’

docker-compose up docker-compose.yml
ERROR: No such service: docker-compose.yml
docker logs db_container
Error: No such container: db_container
$

I attempted this on the kodekloud lab for module docker-compose in docker for beginners section and below are the checks results

  • Tasks not completed!

  • Syntax Check for the docker-compose.yml ? Correct

  • Wordpress running on the correct HostPort? Wrong

  • WordPress linked to db container Wrong

  • db container running with env variable POSTGRES_PASSWORD ? Wrong

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

@KodeKloud @Inderpreet please have a look into it.

Hi @ppnehe @player001
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

@KodeKloud

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