Is it possible to rename the db host name? - ddev

I've got an odd use case where I'm adding DDEV to a project, but for reasons I'd like the db host to be 'mysql' instead of 'db'.
Is this possible?

Try this .ddev/docker-compose.hostname.yaml:
services:
db:
hostname: mysql

Related

When run GITLAB CI then error migrate laravel with service mysql 5.7

enter image description here
Please help me. When gitlab CI instance run then error migrate of laravel , can't connect host mysql
enter image description here
First:
Use Docker with environment variables for deploy everyone :D
Second:
Make cut .env in CI script and show.
Your sed is not working right. It substitutes the variable name with the value, and not your data in the variable value.
Should be something like:
sed -i "s|DB_HOST=|DB_HOST=${DB_HOST}|g" .env
Third: Don't use .env.example for building .env. Build .env file from empty.
You didn't set up your MySQL properly. For services you have MySQL, but no port of it is exposed, NO MySQL root username, password, or database is set.
It should be something like...
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: laravel
ports:
- 33306:3306
Then use that in your project Environment, try this for a complete yml.
If you want SQLite instead of MySQL you can try this

Unable to connect to a running Laravel Sail Docker project with TablePlus (role does not exist)

I created a new Laravel project and installed Sail with composer require laravel/sail --dev followed by php artisan sail:install and sail up to get the project up and running in Docker.
By doing these actions my .env file changed from
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_docker
DB_USERNAME=root
DB_PASSWORD=
to
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=laravel_docker
DB_USERNAME=sail
DB_PASSWORD=password
And now I got two running Docker containers:
laravel-docker_laravel.test_1
laravel-docker_pgsql_1
I'm able to run the basic user migration with sail artisan migrate.
Next up I want to connect Tableplus (or Postico) with my Postgresql database running in Docker. Therefore I filled in the following information:
When trying to connect I got ERROR FATAL: role "sail" does not exist.
Can someone help me out?
Edit 1: Adding a screenshot from some terminal commands. I can connect to the database in the docker container, see a list of the tables and get a table with all the rows from the users table (inserted with a seeder using Laravel Sail)
Edit 2: docker-compose ps
Thanks to this post I found a working solution.
Changing to a different port in the docker-compose.yml file fixed the issue.
Before:
pgsql:
image: 'postgres:13'
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
After:
pgsql:
image: 'postgres:13'
ports:
- '${FORWARD_DB_PORT:-5632}:5432'
After changing the port number to 5632 in TablePlus I'm able to connect to the database.
I have the same problem "role "sail" does not exist". In this case we need to use command ./vendor/bin/sail down -v to delete the existing Docker volume data. After that you can do ./vendor/bin/sail up command.

Connection refused to localhost:5432 through Docker Compose after already specifying the name of the service instead of localhost

I have a few microservices running under Docker. They are Zuul, Eureka, and a configuration server. These are working but when I start my authorization-service, it says I cannot connect to PostgreSQL.
version: '3'
services:
eureka-discovery:
...
zuul-gateway:
...
config:
...
postgres:
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
POSTGRES_DB: spring_microservices
ports:
- 5432:5432
authorization-service:
image: authorization-service:0.0.1
environment:
- eureka.client.serviceUrl.defaultZone=http://eureka-discovery:8761/eureka
- spring.cloud.config.uri=http://zuul-gateway:8765/config-service
- spring.datasource.url=jdbc:postgresql://postgres:5432/spring_microservices
depends_on:
- eureka-discovery
- zuul-gateway
- config
- postgres
ports:
- 1001:1001
What's confusing is that I am specifying postgres instead of localhost to make the connection, but the error continues to say "localhost". You see I override other properties the same way I do with spring.datasource.url and they work but this one.
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
I attempted a few variations I could find around, such as using a different service name, using SPRING_DATASOURCE_URL, using the connection string as postgresql://[user]:[pass]#[service]/[database], I tried moving this line to the config-service instead since the database connection is indeed in the Spring Cloud Config Server microservice, but all to no avail. What's missing? It seems to be correct comparing to all the solutions I found.
I made Spring Config Server see my repository for the configurations. Thinking better, if it's reading from the repository it's evident that changing it on the fly locally won't work, so I updated the connection string of the configuration file for authorization-service then pushed, and it worked. I wonder if this is a good practice or better to make Config Server see local files and change it on the fly?
Hi i hope you are okay !
above your authorization-service add a link like this:
links:
- "postgres"
Greetings

Communication between two ddev projects

I got two ddev projects that needs to interact with each other. When a ran into some issues, I check the resolved IP for the connection.
I did it by ssh into project1 and ping project2 (ping project2.ddev.local)
The domain resolves to 127.0.0.1
So every request I send to this domain will stay in the current container and is not routet to the other project.
Steps to reproduce:
Start two separate ddev containers and ssh into one of them. Try to ping the the other project by using the ddev domain.
Is there a solution that two (or more) projects can interact with each other?
Edit 2019-01-08: It's actually easy to do this with just the docker name of the container, no extra docker-compose config is required. For a db container that's ddev-<projectname>-db. So you can access the db container of a project named "d8composer" by using the hostname ddev-d8composer-db; for example mysql -udb -pdb -h ddev-d8composer-db db
Here's another technique that actually does have two projects communicating with each other.
Let's say that you have two projects named project1 and project2, and you want project2 to have access to the db container from project1.
Add a .ddev/docker-compose.extradb.yaml to project2's .ddev folder with this content:
version: '3.6'
services:
web:
external_links:
- ddev-project1-db:proj1-db
And now project1's database container is accessible from the web container on project2. For example, you can mysql -h proj1-db from within the project2 web container.
Note that this is often a bad idea, it's best not to have two dev projects depend on each other, it's better to figure out development environments that are as simple as possible. If you just need an extra database, you might want to try How can I create and load a second database in ddev? . If you just need an additional web container as an API server or whatever, the other answer is better.
A simple example of extra_hosts. I needed to use an HTTPS URL in a Drupal module's UI, entity_share, to cURL another ddev site.
On foo I add a .ddev/docker-compose.hosts.yaml
version: '3.6'
services:
web:
extra_hosts:
- bar.ddev.site:172.18.0.6
I tried this and it worked quite nicely; the basic idea is to run a separate ddev-webserver as a service. We usually think of a ddev "service" as something like redis or memcache or solr, but it can really be an API server of any type, and can use the ddev-webserver image (or any other webserver image you want to use).
For example, add this docker-compose.api.yaml to your project's .ddev folder (updated for ddev v1.1.1):
version: '3.6'
services:
myapi:
image: drud/ddev-webserver:v1.1.0
restart: "no"
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
com.ddev.app-url: $DDEV_URL
volumes:
- "../myapi_docroot/:/var/www/html:cached"
- ".:/mnt/ddev_config:ro"
web:
links:
- myapi:$DDEV_HOSTNAME
and put a dummy index.html in your project's ./myapi_docroot.
After ddev start you can ddev ssh -s myapi and do whatever you want there (and myapi_docroot is mounted at /var/www/html). If you ddev ssh into the web container you can curl http://myapi and you'll see the contents of your myapi_docroot/index.html. Your myapi container can access the 'db' container, or you can run another db container, or ...
Note that this mounts a subdirectory of the main project as /var/www/html, but it can actually mount anything you want. For example,
volumes:
- "../../fancyapiproject/:/var/www/html:cached"

Docker Oracle Database - can't overwrite ENV variables for credentials

I would like to configure an Oracle database on a server. For that, I am using this image from DockerHub:
https://hub.docker.com/r/sath89/oracle-12c/
Having included the image in a docker-compose.yml file, I am having trouble with overwriting the default credentials for accessing the database (the username is system while the password is oracle). This is how my docker-compose.yml file looks like:
version: '3.5'
services:
oracle12c-db:
image: sath89/oracle-12c
restart: always # restart policy
ports:
- 1521:1521
environment:
- USER=myusername
- PASS=mypass
- HOST=oracle-database
- PORT=1521
- ORACLE_SID=XE
- HTTP_PORT=8080
After successfully executing the command docker-compose up, I am still not able to access the database with the new credentials (only with the default ones). Is my docker-compose file syntactically correct or am I missing out something else here? Thanks in advance for your help!
I don't you can modify this at run time particularly easily.
Option 1 is to create your own Dockerfile based on theirs and pass in the user and password at build time (or hard code it to something else)
Option 2 is to modify their entrypoint and run the appropriate Oracle commands at startup to change the user/password

Resources