Docker-compose not creating links between containers

I have a very simple 2 container application, 1 running Tomcat the other Redis. I am attempting to use docker-compose but the link between the containers is not working.

If I simply do a run with the below commands all is happy.
docker run -d --name db redis
docker run -d -P --name web --link db web

When I attempt to use the below docker-compose.yml file there is no link between the containers.
version: '2’
services:
web:
image: web
links:
- redis
ports:
- "8080:8080"
redis:
image: redis

There are no environment variables created using docker-compose and the /etc/hosts file is not updating.

I’m puzzled since this is literally a copy of several of the examples I’ve found on numerous site, including docker.com. Any help would be greatly appreciated.

No such image as “web” exists.
The formatting also has to be applied.

The following compose file runs fine.
version: ‘2’
services:
web:
build: “.”
command: “bundle exec rails s -p 3000 -b ‘0.0.0.0’”
links:
-
db
ports:
-
“3000:3000”
volumes:
-
“.:/rubyapp”
db:
image: mysql
environment:
-
MYSQL_ROOT_PASSWORD=mysql

In version 2 of compose you don’t need links. You should be able to connect to the redis container just be referring to the hostname redis. It doesn’t appear in environment variables or /etc/hosts as networking is now a first-class feature in docker, and instead it uses built-in DNS resolution.

Since the new networking model came in, each container is started on a network (default by er, default) and can communicate with each other by using their service or container name.

Also refer