rancher network docker-compose - docker

compose this .yml
version: '2'
services:
wordpress:
image: wordpress:latest
expose:
- 80
restart: always
networks:
- nginx-proxy
environment:
- VIRTUAL_HOST=blog.gerling.one
container_name: wordpress
networks:
nginx-proxy:
external: true
when i run the docker-compose.yml with
docker-compose up
the container starts with Network: nginx-proxy -> all Works
but when i start with
rancher-compose <API SETTINGS> up
the container starts with Network: Managed and nothing works
Yeah its right that nothing works but how i can start with nginx-proxy in rancheros?
Thanks for the help.

Networking in Rancher is different from Docker. So the docker compose file doesn't work as-is. To achieve what you are trying to accomplish there are a few options:
Checkout the Wordpress Catalog item in Rancher Catalog
Manually start Wordpress service and create a Load Balancer in Rancher UI and use the Host information there.

Related

setup networking of multiple docker containers in different projects using docker-compose

Hello I have multiple projects that have there own dockerfiles and docker-compose.yml files. I am not too familiar on how I would setup the networking between these projects. So they could share the same databases and the project would be able to talk to on another. Does anyone have suggests?
Right now, In one of the projects I am just pulling in all the dockerfile into a docker-compose.yml and setting-up all the services I need from all the other projects in this yml file. I do not think this is ideal and there is a high level a coupling between the services.
version: "3"
services:
db:
image: mysql/mysql-server
ports:
- 3306:3306
mongo:
image: mongo
restart: always
rails_app:
build:
context: ${RAILS_APP_PATH}
dockerfile: Dockerfile
volumes:
- ${RAILS_APP_PATH}:/application
ports:
- 4000:4000
depends_on:
- db
- mongo
links:
- db
- mongo
frontend:
build:
context: ${FRONTEND_PATH}
ports:
- ${EXPOSED_PORT}:${EXPOSED_PORT}
depends_on:
- go_services
links:
- go_services
go_services:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- db
- mongo
- rails_app
links:
- db
- mongo
- rails_app
The trick is to use an External Docker Network.
Set up the network and the Containers can talk to each other by their Service Names.
Setup the the network on the Host
docker network create my-net
First compose file
version: '3.9'
services:
mymongo:
image: mongo:latest
restart: unless-stopped
container_name: mongo
environment:
MONGO_INITDB_DATABASE: mymongo
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
volumes:
- ./database:/data/db
ports:
- "27017:27017"
networks:
default:
external: true
name: my-net
Second compose file
version: '3.9'
services:
ui:
build:
context: ./build
dockerfile: Dockerfile_ui
image: ui
restart: "no"
container_name: ui
ports:
- "8005:3000"
command: ["npm", "start"]
networks:
default:
external: true
name: my-net
You can do this without any special Compose setup, if:
each project is self-contained (they do not share databases)
the service locations are configurable via environment variables
you don't mind communicating via the host
If you're thinking about scaling up this project at all, this approach can look attractive. It will work even if you're running each Compose file on a different host, and it translates well into clustered environments like Kubernetes.
Go ahead and break up your Compose file into several independent ones:
# rails/docker-compose.yml
version: '3.8'
services:
db:
image: mysql/mysql-server
app:
build: .
ports: ['4000:4000']
depends_on: [db]
# go/docker-compose.yml
services:
mongo:
image: mongo
service:
build: .
ports: ['8080:8080']
depends_on: [mongo]
environment:
- RAILS_APP_URL
The very last line here passes the RAILS_APP_URL environment variable from the host environment into the container.
You can start the Rails application independently:
docker-compose -f ./rails/docker-compose.yml up -d
You need to find some hostname where the container can call back to the host. On MacOS and Windows hosts, Docker provides a special hostname host.docker.internal for this. You can then connect the client container to the published port of its server:
export RAILS_APP_URL=http://host.docker.internal:4000
docker-compose -f ./go/docker-compose.yml up
If you're doing development, you can run the service you're working on locally, and its dependencies in containers, and point the environment variable at the container
go build -o ./server ./cmd/server
export RAILS_APP_URL=http://localhost:4000
./server
If you want to run this setup on multiple hosts but without using a dedicated cluster manager like Docker Swarm or Kubernetes, set the environment variable to point at the DNS name of the host running the service. If you did want to translate this to Kubernetes, a Helm "chart" would be analogous, containing the Deployment, Service, etc. and dependencies for a single component, and you could configure the other service's URL through Helm values.

Docker communication inside docker compose and with database which is outside docker

I'm little bit confused with docker and network communication. I tried many things but it didn't work :-(.
I have following docker compose:
version: '3'
services:
nginx:
container_name: nginx
image: nginx:stable-alpine
restart: unless-stopped
tty: true
ports:
- 80:80
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d:ro
depends_on:
- app
networks:
- frontend
- backend
app:
restart: unless-stopped
tty: true
build:
context: .
dockerfile: Dockerfile
container_name: app
expose:
- "9090"
ports:
- 9090:9090
networks:
- backend
networks:
frontend:
backend:
And I would like to communicate:
From nginx to app //this probably works
From app to postgreSQL which is installed on server (no docker container)
I cannot do this, I tried many things but something is wrong :-(
You can choose any of these two options:
Make your postgresql listen to all your network interfaces (or the docker bridge for more secure but complex setup), to achieve that you need to make sure your config looks like this:
# grep listen /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'
Use host network mode in your docker compose, which runs docker in your host network name space instead of creating a new network:
network_mode: "host"

Aspnet core application is not running after docker host or container restart

I'm running containers with restart policy as always through docker-compose, it has two images RabbitMq & AspNetCore,it all works fine for the first time.
when I restart the host or docker containers then RabbitMq is running fine and accessible through localhost:8080 even after restarting, but aspnet core project container is running but I can't access through internal and external ( localhost:5001/api/home/get) ports.
Docker compose
version: '3.4'
services:
aspnetcoreenvironmentvariables.api:
image: aspnetcoreenvironmentvariables
build:
context: .
dockerfile: AspNetCoreEnvironmentVariables.API/Dockerfile
restart: always
depends_on:
- rabbitmq
rabbitmq:
image: rabbitmq:3-management
restart: always
Docker compose override
version: '3.4'
services:
aspnetcoreenvironmentvariables.api:
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ConnectionStrings__DefaultConnection="connection"
ports:
- "5001:80"
rabbitmq:
ports:
- "8080:15672"
Below is error from docker

Docker Swarm with docker compose version 3 hostname underscore issue

I have created a docker swarm and trying to use overlay network in order to communicate between the 2 services deployed over that swarm.
the Docker compose of 1 service looks like:
version: '3'
services:
web:
container_name: "eureka"
image: eureka
environment:
EUREKA_HOST: eureka
ports:
- 8070:8070
networks:
- net_swarm
networks:
net_swarm:
external:
name: net_swarm
Second :
version: '3'
services:
web:
image: zuul-service
environment:
EUREKA_HOST: eureka_web
ports:
- 8069:8069
networks:
- net_swarm
networks:
net_swarm:
external:
name: net_swarm
i did a docker deploy --compose-file docker-compose.yml eureka to create the service 1, which spun up with service name as eureka_web, as seen above the same is referenced in the compose file of service 2 as EUREKA_HOSTS, however since this "eureka_web" has an underscore the host isnt getting picked when trying to run the second file.(primarily becoz of the underscore)
Can i somehow override the underscore in the service name or is there any other work around?
Don't give the container name.
So that your service name will act as the host name.
Also the host name with underscores should not cause any problem. Try finding out the actual rootcause.
Edit:
Your service name and the host name is web. And I can't say about this line, without looking at the docker file.
environment:
EUREKA_HOST: eureka

Keep containers alive using docker-compose on windows

I have two services defined in docker-compose.yml file and expecting two containers up and running in output however the containers are getting stopped immediately. When I use the same compose file on Linux it creates and keep twp containers up and running. Is there any known issue with Windows?
I have tried using docker-compose up as well as docker-compose run -dT <servicename> no go.
my docker-compose.yml file is
version: '3'
networks:
default:
external:
name: nat
services:
awi-service:
env_file:
- awi-box.env
image: awi-box:12.0.0
ports:
- 8080:8080
depends_on:
- ae-service
ae-service:
env_file:
- ae-box.env
image: ar-box:12.0.0
ports:
- 2217:2217
- 2218:2218

Resources