How to change "localhost" name on docker php-apache? - docker

I'm using php-apache image on Docker. I want to change my default domain name, from localhost, to another one.
So instead of http://localhost:81, I need to connect by: http://mycustomname:81
How I can achieve this?

Related

How automate setting default Name (general page), Host Name/address, Username, Pass(connection page) creating server in pgadmin4 using docker-compose?

I am beginner in docker. I want to automate process for my teammates.
How can I set default labels for Name, Host Name/address, Username, Password in pgAdmin4 via docker-compose? Or probably I have to use Dockerfile?
How can I automate connection pgAdmin4 to the db server via docker-compose or docker?
Thanks!
You can export the saved servers to a servers.json file (https://www.pgadmin.org/docs/pgadmin4/6.5/import_export_servers.html#json-format) and then map the file in docker-compose(https://www.pgadmin.org/docs/pgadmin4/6.5/container_deployment.html - PGADMIN_SERVER_JSON_FILE)

How to use local DNS in Pyppeteer

I've got a reverse proxy, frontend and backend container. The backend is running Pyppeteer and the reverse proxy is set up with an alias "servicename.localhost" in docker-compose.yml:
networks:
default:
aliases:
- servicename.localhost
This way I'm able to curl --insecure https://servicename.localhost from the backend container, but unfortunately it seems Chromium on the same container ignores that setting and so "servicename.localhost" resolves to 127.0.0.1:
pyppeteer.errors.PageError: net::ERR_CONNECTION_REFUSED at https://servicename.localhost/login
How can I work around this?
It looks like it may be related to DNS prefetching or asynchronous DNS, but there doesn't seem to be a command line flag to disable either of them anymore.
Things I've tried which didn't change anything:
Adding "--host-rules='MAP servicename.localhost {}'".format(socket.gethostbyaddr('servicename.localhost')[-1][0]) to the pyppeteer.launch args list parameter.
Adding "--host-resolver-rules=[same as above] to the pyppeteer.launch args list parameter.
I worked around this by changing the TLD from "localhost" to "test".

Docker container names

I'm using Docker on Rails project. I found only one way to reliably link services between each other, i. e. specifying container_name in docker-compose.yml:
version: '3'
services:
db:
container_name: sociaball_db
...
web:
container_name: sociaball_web
...
sphinx:
container_name: sociaball_sphinx
...
So now I can write something like this in database.yml and stop worrying about, say, database container randomly changing its name from db to db_1:
common: &common
...
host: sociaball_db
However, I can only run three containers at the same time. Whenever I try to run docker-container up if some containers aren't down it will raise an error.
ERROR: for sociaball_db Cannot create container for service db: Conflict. The container name "/sociaball_db" is already in use by container "ee787c06db7b2a0205e3c1e552b6a5496545a78fe12d942fb792b27f3c38769c". You have to remove (or rename) that container to be able to reuse that name.
It is very inconvenient. It often forces explicitly deleting all the containers just to make sure they have no opportunity to break. Is there a way around that?
When running several containers from one compose file, there will be a default network where all containers are attached to (if not specified differently).
There is no need to reference a container by its container or hostname as docker-compose automatically sets up some dns service discovery where each docker-compose service can be resolved by its service name (the key used one level below services:.
So your service called web can reach your database using the name db. No need to specify a container name for this use case. For more details please see the docker docs on networking that also demonstrates a rails app accessing a database.

Stack service containers dynamic hostname

I am migrating away from Docker Cloud to pure Docker Swarm setup. One thing that I am missing is the nice way of how the containers got the hostname set as $SERVICE_NAME-$SLOT_NUMBER.
Is it possible to dynamically set the hostname/container name in a swarm stack service?
In your stack/compose file, use this format:
services:
thaservice:
...
hostname: "{{.Service.Name}}-{{.Task.Slot}}"
Link to documentation for available template variables: https://docs.docker.com/engine/swarm/services/#create-services-using-templates

Host names are not set in docker compose

I created simple compose config to try Postgres BDR replication.
I expect containers to have host names as service names I defined and I expect one container to be able to resolve and reach another with this hostname. I expect it to be true because of that:
https://docs.docker.com/compose/networking/
My config:
version: '2'
services:
bdr1:
image: bdr
volumes:
- /var/lib/postgresql/data1:/var/lib/postgresql/data
ports:
- "5001:5432"
bdr2:
image: bdr
volumes:
- /var/lib/postgresql/data2:/var/lib/postgresql/data
ports:
- "5002:5432"
But in reality both containers get rubbish hostnames and are not reachable by container names:
Creating network "bdr_default" with the default driver
Creating bdr_bdr1_1
Creating bdr_bdr2_1
Attaching to bdr_bdr1_1, bdr_bdr2_1
bdr1_1 | Hostname: 938e0585fee2
bdr2_1 | Hostname: 7153165f4d5b
Is it a bug, or I did something wrong?
I use Ubuntu 14.04.4 LTS, Docker version 1.10.1, build 9e83765, docker-compose version 1.6.0, build d99cad6
docker-compose gives you the option of scaling services up or down, meaning you can launch multiple instances of the same service. That is at least one reason why the hostnames are not just service names. You will notice that if you scale bdr1 to 2 instance, you will then have bdr_bdr1_1 and bdr_bdr1_2 containers.
You can work around this inside the containers that were started up by docker-compose in at least two ways:
If a service refers to other service, you can use links section, for example make bdr1 link to bdr2. In this case when you are inside bdr1 you can call host bdr2 by name. I have not tried what happens when you scale up bdr2 in this case.
You can force the hostname of a container internally to the name you want by using the hostname section. For example if you add hostname: bdr1 to bdr1, then you can internally connect to bdr1, which is itself.
You can possibly achieve similar result with the networks section, but I have not yet used it myself so I don't know for sure.
The hostname inside the container should be the short container id, so this is correct (note there was a bug with Compose 1.6.0 and the short container id, so you should use at least version 1.6.2). Also /etc/hosts is not longer used, there is now an embedded dns server that handles resolving names to container ip addresses.
The container is discoverable by other containers with 3 names: the container name, the container short id, and the service name.
However, the other container may not be available immediately when the first one starts. You can use depends_on to set the order.
If you are testing the discovery, try using ping, and make sure to retry , because the name may not resolve immediately.

Resources