Accessing localstack from another computer - docker

I have localstack running on a Kali Linux box. I have added an aws S3 service. I can access the service using:
aws --endpoint-url=http://localhost:4566 s3 ls
if I try the same command using the machines IP address I get a message:
Could not connect to the endpoint URL: "http://10.xxx.xxx.xxx:4566/"
My docker-compose.yaml file looks like:
version: "3.8"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
- "127.0.0.1:53:53" # DNS config (only required for Pro)
- "127.0.0.1:53:53/udp" # DNS config (only required for Pro)
- "127.0.0.1:443:443" # LocalStack HTTPS Gateway (only required for Pro)
environment:
- DEBUG=${DEBUG-}
- PERSISTENCE=${PERSISTENCE-}
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY-} # only required for Pro
- DOCKER_HOST=unix:///var/run/docker.sock
- HOSTNAME_EXTERNAL-localstack
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
default:
external: true
name: localstack
I am not sure how to tell localstack to be available by the machine's IP address instead of just localhost.
Thank in advance for the help.:

Related

The Docker container cannot access other services on the intranet of the host company

version: "3.7"
services:
tomcat:
image: tomcat:9
container_name: tomcat-change
ports:
- "18080:8080"
volumes:
- "./my.war:/usr/local/tomcat/webapps/my.war"
entrypoint:
- "catalina.sh"
- "run"
networks:
- mywork
networks:
mywork:
name: mywork
driver: bridge
ipam:
driver: default
config:
- subnet: 172.31.0.0/24
gateway: 172.31.0.1
this is my docker-compose.yml
The company's LAN IP address is 172.17.xxx.xxx
My local area network IP address is 172.17.6.xxx
There is an ordinary db server in the LAN 172.17.1.xxx
I run docker compose locally The yml Docker intranet cannot connect to the database of 172.17.1.xxx
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 172.17.1.xxx, port 1433 has failed. Error: "Connect timed out. Verify the connection properties. Make sure that an instance of SQL Ser
ver is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall
It is normal to start locally without using Docker
I use the window Docker Desktop
Docker version 20.10.11, build dea9396
ersion: "3.7"
services:
tomcat:
image: tomcat:9
container_name: tomcat-change
ports:
- "18080:8080"
volumes:
- "./my.war:/usr/local/tomcat/webapps/my.war"
entrypoint:
- "catalina.sh"
- "run"
extra_hosts:
- "db:172.17.1.xx"
This is all you need in the docker-compose.yml. Replace 172.17.1.xx with the ip of your database server. In your application refer to the database host by db.

How to connect with database(mongodb in server 2) from docker container (running in server 1)

Server 1->10.0.0.47
Server 2->10.0.1.202
All ports between these two servers are open as they are in same VPN in aws
version: '3.3'
networks:
net:
external: true
services:
backend:
image: test/test-backend:prod
ports:
- "8000:8000"
depends_on:
- discovery
ERROR:Connection refused
Note When i try to change the composer like below
connection with mongo established but unable to access the service on port 8000
networks:
net:
external: true
services:
backend:
image: test/test-backend:prod
expose:
- "27017:27017"
ports:
- "8000:8000"
depends_on:
- discovery
The Expose instruction does not change anything, it's for documentation only. You can read more about it in the Dockerfile reference.
If the 2 Server are in the same Docker network, you could change the mongoDB port to 8000 in its installation configuration. Then, you don't need to specify a port etc. in the docker-compose configuration.
If you want to access the mongoDB service from outside, you have to change the docker-compose configuration to:
ports:
- "8000:27017"

Deploying a docker private registry that supports IPv6

I am trying to deploy a private docker registry that supports IPv6. I followed the steps here to define my IPv6 address.
docker-compose.yml
version: '2.1'
services:
registry:
restart: always
image: registry:2
ports:
- "5000:5000"
environment:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry
REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
volumes:
- ./auth:/auth
- ./data:/data
networks:
dock_net:
ipv6_address: 2001:db8::10
networks:
dock_net:
enable_ipv6: true
driver: bridge
ipam:
driver: default
config:
- subnet: 2001:db8::/32
gateway: 2001:db8::1
As far as I can tell it "works". A docker inspect shows the global IP address as the one I defined. I can ping the address, but if I issue curl -u username:password http://[<ipv6 address>]:5000/v2/_catalog on the host system (the one hosting the repository) it fails with no route to host.
Is there a step I missed during setup?
If need to be accessible from internet - you can put it behind cloudflare, and it will be accessible from both ipv6 and ipv4.

Accessing Docker from host network using domain name

hey guys I have a docker container A with a domain name attached to it on a host B with a domain name attached to it as well.....how can I access the said container A via A's domain name rather than an B's ip address or domain name from computer C on the host B's local network.
thus C -> A( via wwww.cname.url) rather than C -> B( www.bname.url:port) -> A
E.G.
the following is a docker-compose with services
version: "3.2"
services:
php:
links:
- mysql
image: arm32v6/php:7.1.24-fpm-alpine3.8-lavalite
networks:
- backend
working_dir: /var/www/html
volumes:
- ./website/:/var/www/html/
privileged: true
node:
domainname: docker.local
hostname: node
networks:
frontend:
aliases:
- node.docker.local
links:
- "apache:dev.docker.local"
depends_on:
- apache
image: arm32v7/node:latest
entrypoint: yarn
command: twill-dev
volumes:
- ./website:/usr/src/app
working_dir: /usr/src/app
ports:
- "3000:3000"
- "3001:3001"
apache:
domainname: docker.local
hostname: dev
image: arm32v7/httpd:2.4
depends_on:
- php
- mysql
networks:
frontend:
aliases:
- apache
- dev.docker.local
backend:
aliases:
- apache
privileged: true
ports:
- "8880:80"
working_dir: /var/www/html
volumes:
- ./website/:/var/www/html/
- ./httpd.conf:/usr/local/apache2/conf/httpd.conf
- ./fpm.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf
mysql:
image: yobasystems/alpine-mariadb:arm32v7
volumes:
- ./datadir:/var/lib/mysql
networks:
- backend
environment:
- MYSQL_VERSION=5.7
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_USER=test
- MYSQL_PASSWORD=testpass
- MYSQL_DATABASE=test_db
networks:
frontend:
external:
name: localnet
backend:
I want to be able to access service apache by its domain name set to dev.docker.local the ip of which is on a network 17.18.0.1/24
The host has an IP which is on a network 192.168.1.0/24 with a domain name dev.server.local
I have a dev pc on the network 192.168.1.0/24 and it can access the service containers via the hosts IP and usually a port exposed for the particular service.
UPDATE
The host can be reached at server.local from outside the network
my network interface has the following entries
dns-search server.local
dns-domain server.local
the docker container has the following
hostname nginx
domainname server.local
do I need to also edit a host file or resolv.conf file?
It seems the host is running avahi service discovery. Would this affect anything?
So can I
set an internal domain set to the host and have docker containers on subdomains? How would outside devices access this via the domain?
attach the docker container to be on the host's network thus having an ip in the 192.168.1.0/24 and being able to be pinged by devices on that network as well. Will the domain resolve to it?
Is there a dynamic DNS software I can use that can hook this up to me so that its not a manual process. Thus it will detect the server and route incoming requests to it via the domain name?
You can do this by configuring an nginx container with the containers bound to the subdomain.
So for example the host is accessible by domain example.com and you want the php container to be accessible on php.example.com you could use a setup like the following:
services:
php:
image: arm32v6/php:7.1.24-fpm-alpine3.8-lavalite
environment:
- VIRTUAL_HOST=php.example.com
nginx-proxy:
image: jwilder/nginx-proxy
depends_on:
- php
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
Any request to the subdomain would first be send to the host, this is bound by nginx, which in turn registers that because the subdomain php is requested it should send the user to that container.
I hope this can help you and if you have any questions please let me know

jhipster seperate services during development

Goal
We would like to create a development environment where we can run the latest versions of our registry, uaa and gateway on a server. We would then like to develop and run (in or outside docker) a microservice locally. This microservice should then be configured to connect and communicate to the other server.
Test setup
I have now generated a docker-compose via the jhipster sub-generator for our gateway, uaa and registry. I then tried to start the microservice i'm currently working on via gradlew, build it via gradlew dockerBuild and start the app.yml. I also tried to change the hostname in app.yml to localhost, 127.0.0.1 and the IP of the registries docker container.
My results
If hostname is jhipster-registry: unknownhostexception. Most likely because the applications are started in different docker-compose files.
If hostname is localhost or 127.0.0.1: http://127.0.0.1:8761/config/application/prod/master connection refused. Changing to Perhaps some more configuration is required?
If the hostname is the ip of the registry docker container: After the jhipster logo in the terminal no other output is given. But the application never stops due to an exception.
Files
docker-compose.yml (registry, uaa & gateway)
version: '2'
services:
mygateway-app:
image: mygateway
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/config
- SPRING_DATASOURCE_URL=jdbc:mysql://mygateway-mysql:3306/mygateway?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=30
- JHIPSTER_REGISTRY_PASSWORD=admin
ports:
- 8080:8080
depends_on:
- "mygateway-mysql"
- "myuaa-app"
mygateway-mysql:
image: mysql:5.7.20
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=mygateway
command: mysqld --lower_case_table_names=1 --skip-ssl
--character_set_server=utf8mb4 --explicit_defaults_for_timestamp
myuaa-app:
image: myuaa
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/config
- SPRING_DATASOURCE_URL=jdbc:mysql://myuaa-mysql:3306/myuaa?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=30
- JHIPSTER_REGISTRY_PASSWORD=admin
depends_on:
- "myuaa-mysql"
- "jhipster-registry"
myuaa-mysql:
image: mysql:5.7.20
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=myuaa
command: mysqld --lower_case_table_names=1 --skip-ssl
--character_set_server=utf8mb4 --explicit_defaults_for_timestamp
jhipster-registry:
extends:
file: jhipster-registry.yml
service: jhipster-registry
app.yml (microservice)
version: '2'
services:
myservice-app:
image: myservice
environment:
# - _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}#localhost:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}#localhost:8761/config
- SPRING_DATASOURCE_URL=jdbc:mysql://myservice-mysql:3306/myservice?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=10 # gives time for the JHipster Registry to boot before the application
- JHIPSTER_REGISTRY_PASSWORD=admin
myservice-mysql:
extends:
file: mysql.yml
service: myservice-mysql
# jhipster-registry:
# extends:
# file: jhipster-registry.yml
# service: jhipster-registry
# environment:
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config/docker-config/

Resources