Following along with the Docker getting started guide, https://docs.docker.com/get-started/part3/#your-first-docker-composeyml-file, I'm running into an issue. I've created the docker-compose.yml file and verified that the contents are correct:
version: "3"
services:
web:
image: joshuabelden/get-started:part2
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
I also verified that I can run my image outside of a swarm. After running the command:
docker stack deploy -c docker-compose.yml getstartedlab
I'm getting the following error:
Top-level object must be a mapping
I can't seem to find any information on the error message.
What I did to solve this is I removed the double quotes and made them single quotes to change version: "3" -> version: '3' This removed the error for me, also do this for all double quotes.
You have to add the "volumes" where your code should be copied:
version: "3"
services:
web:
image: iconkam/get-started:part2
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
volumes:
- .:/app
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
This happens when Docker is running in Kubernetes mode and not swarm.
I fixed it by changing it to Swarm through settings > Kubernetes
You probably didn't save after modifying the docker-compose.yml file. So if you run 'docker compose up' without having saved, you get the error about top-level object mappings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With