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