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

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

Related

How to connect to external FTP from NiFi running in docker container?

I have:
NiFi running in docker container. I'm running NiFi via Docker Compose with the following config:
version: '3'
services:
nifi:
image: apache/nifi:latest
container_name: nifi
ports:
- "8443:8443"
volumes:
- ./database_repository:/opt/nifi/nifi-current/database_repository
- ./flowfile_repository:/opt/nifi/nifi-current/flowfile_repository
- ./content_repository:/opt/nifi/nifi-current/content_repository
- ./provenance_repository:/opt/nifi/nifi-current/provenance_repository
- ./state:/opt/nifi/nifi-current/state
- ./logs:/opt/nifi/nifi-current/logs
- ./conf:/opt/nifi/nifi-current/conf
restart: always
FTP server located on localhost (outside the container)
In the NiFi route i'm using a GetFTP processor which tries unsuccessfully to connect to localhost:21
I understand that the problem is that localhost is not available, because container is isolated. What and how to configure in the docker-compose.yml configuration to solve the problem?

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.

rancher network docker-compose

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.

Mapping ports in docker-compose file doesn't work. Network unreachable

I'm trying to map a port from my container, to a port on the host following the docs but it doesn't appear to be working.
After I run docker-compose -f development.yml up --force-recreate I get no errors. But if I try to reach the frontend service using localhost:8081 the network is unreachable.
I used docker inspect to view the IP and tried to ping that and still nothing.
Here is the docker-compose file I am using. And I doing anything wrong?
development.yml
version: '3'
services:
frontend:
image: nginx:latest
ports:
- "8081:80"
volumes:
- ./frontend/public:/var/www/html
api:
image: richarvey/nginx-php-fpm:latest
ports:
- "8080:80"
restart: always
volumes:
- ./api:/var/www/html
environment:
APPLICATION_ENV: development
ERRORS: 1
REMOVE_FILES: 0
links:
- db
- mq
db:
image: mariadb
restart: always
volumes:
- ./data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: dEvE10pMeNtMoDeBr0
mq:
image: rabbitmq:latest
restart: always
environment:
RABBITMQ_DEFAULT_USER: developer
RABBITMQ_DEFAULT_PASS: dEvE10pMeNtMoDeBr0
You are using docker toolbox. Docker toolbox uses docker machine. In Windows with docker toolbox, you are running under a virtualbox with its own IP, so localhost is not where your containers live. You will need to go 192.168.99.100:8081 to find your frontend.
As per the documentation on docker machine(https://docs.docker.com/machine/get-started/#run-containers-and-experiment-with-machine-commands):
$ docker-machine ip default
192.168.99.100

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