Join our Discord Server
Getting Started

Lab 3: The ‘Config’ Command

Estimated reading: 2 minutes 97 views

The docker-compose config command validate the docker-compose file and view the compose file.

Pre-requisite:

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

  • Create an account with DockerHub
  • Open PWD Platform on your browser
  • Click on Add New Instance on the left side of the screen to bring up Alpine OS instance on the right side

Assignment

  • Create a docker-compose.yml file
  • Validate the docker-compose file
  • Testing docker-compose config with wrong config

Create a docker-compose.yml file

Copy the below contents:

version: '3.1'
services:
  #Nginx Service
   webserver:
     image: nginx:alpine
     container_name: webserver
     restart: unless-stopped
     ports:
       - "80:80"
       - "443:443"

Or Clone the repository:

git clone https://github.com/collabnix/dockerlabs
cd intermediate/workshop/compose/lab/3/config/
cat docker-compose.yml

Validate the docker-compose file

$ docker-compose config
services:
  webserver:
    container_name: webserver
    image: nginx:alpine
    ports:
    - 80:80/tcp
    - 443:443/tcp
    restart: unless-stopped
version: '3.1'

Testing docker-compose config with wrong config

Lets just change the instruction services to service and test.

$docker-compose config

ERROR: The Compose file './docker-compose.yml' is invalid because:
Invalid top-level property "service". Valid top-level sections for this Compose file are: services, secrets, version, networks, volumes, and extensions starting with "x-".

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 https://docs.docker.com/compose/compose-file/
Share this Doc

Lab 3: The ‘Config’ Command

Or copy link

CONTENTS
Join our Discord Server