Docker compose, running containers in net:host

+1 vote

I want to spawn 3 services in the "host" net using docker-compose. Here is my docker-compose.yml file:

version: '2'
services:
  mysql:
    image: mysql
    net: "host"
  nginx:
    image: nginx
    net: "host"
  app:
    image: tomcat
    net: "host"

I got the following error:

$ docker-compose up
[31mERROR[0m: Validation failed in file '.\docker-compose.yml', reason(s):
Unsupported config option for services.app: 'net'
Unsupported config option for services.mysql: 'net'
Unsupported config option for services.nginx: 'net'

I'm using boot2docker on windows.

Docker, and Docker-compose version:

$ docker -v
Docker version 1.10.2, build c3959b1
$ docker-compose -version
docker-compose version 1.6.0, build cdb920a

If I run all services manually by using docker run --net = "host" everything is working fine.

Jul 31, 2018 in Docker by Hannah
• 14,070 points
1,484 views

4 answers to this question.

0 votes

Just print

network_mode: "host"

This might not work for Mac.

answered Jul 31, 2018 by Kalgi
• 40,440 points
network_node worked like a charm, Thanks @Kalgi
+1 vote
This is most probably a syntax error. Please check your code's indentation.
answered Apr 26 by Gargi
Hey @Gargi, the syntax seems fine to me. Can you please share some syntax reference I can compare my syntax with? That would be very helpful

Have a look at this for understanding the syntax.

+1 vote

The reason for this error is that there is an attempt to use a compose file option that is incompatible with the engine version that you're using against. 

In your case, the compose version is 1.6 and you're using version 2 in your Dockerfile.

answered May 7 by Aliba
+1 vote

Hey@Hannah, Check the compose file format specifications and compatibility matrix for what version of the file supports your option.

answered May 7 by Kishore

Related Questions In Docker

0 votes
1 answer

Different file owner inside Docker container and in host machine Ask

Filesystems, at least in Unix- and Linux-like ...READ MORE

answered Jun 25, 2018 in Docker by Damon Salvatore
• 5,510 points
72 views
0 votes
1 answer

Different file owner inside Docker container and in host machine

Here is what you can try. Since ...READ MORE

answered Jun 27, 2018 in Docker by Atul
• 10,240 points
187 views
+1 vote
5 answers

Set containers timezones by using docker compose.

version "2" services: serviceA: ...READ MORE

answered Jul 8, 2018 in Docker by Atul
• 10,240 points
2,547 views
0 votes
1 answer

How to obtain the Docker container's IP address from the host?

This can be done by executing the ...READ MORE

answered Jul 16, 2018 in Docker by Sophie may
• 9,530 points
392 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,520 points
154 views
0 votes
2 answers
+2 votes
6 answers