Service "postgis" fails to start in GitLab CI - docker

I am trying to use the Docker image "postgis/postgis:latest" as a service in GitLab CI but the service fails to start.
This is the start of the CI log, the last line is most important:
Running with gitlab-runner 12.9.0 (4c96e5ad)
on xxxxxxx xxxxxxxx
Preparing the "docker" executor
Using Docker executor with image node:lts-stretch ...
Starting service redis:latest ...
Pulling docker image redis:latest ...
Using docker image sha256:4cdbec704e477aab9d249262e60b9a8a25cbef48f0ff23ac5eae879a98a7ebd0 for redis:latest ...
Starting service postgis/postgis:latest ...
Pulling docker image postgis/postgis:latest ...
Using docker image sha256:a412dcb70af7acfbe875faea4467a1594e7cba3dfca19e5e1c6bcf35286380df for postgis/postgis:latest ...
Waiting for services to be up and running...
*** WARNING: Service runner-xxxxxxxx-project-1-concurrent-0-postgis__postgis-1 probably didn't start properly.
Health check error:
service "runner-xxxxxxxx-project-1-concurrent-0-postgis__postgis-1-wait-for-service" timeout
Health check container logs:
Service container logs:
2020-04-06T11:58:09.487216183Z The files belonging to this database system will be owned by user "postgres".
2020-04-06T11:58:09.487254326Z This user must also own the server process.
2020-04-06T11:58:09.487260023Z
2020-04-06T11:58:09.488674041Z The database cluster will be initialized with locale "en_US.utf8".
2020-04-06T11:58:09.488696993Z The default database encoding has accordingly been set to "UTF8".
2020-04-06T11:58:09.488704024Z The default text search configuration will be set to "english".
2020-04-06T11:58:09.488710330Z
2020-04-06T11:58:09.488716134Z Data page checksums are disabled.
2020-04-06T11:58:09.488721778Z
2020-04-06T11:58:09.490435786Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
2020-04-06T11:58:09.490649106Z creating subdirectories ... ok
2020-04-06T11:58:09.490656485Z selecting dynamic shared memory implementation ... posix
2020-04-06T11:58:09.525841255Z selecting default max_connections ... 100
2020-04-06T11:58:09.562735034Z selecting default shared_buffers ... 128MB
2020-04-06T11:58:09.614695491Z selecting default time zone ... Etc/UTC
2020-04-06T11:58:09.616784837Z creating configuration files ... ok
2020-04-06T11:58:09.917724902Z running bootstrap script ... ok
2020-04-06T11:58:10.767115421Z performing post-bootstrap initialization ... ok
2020-04-06T11:58:10.924542026Z syncing data to disk ... ok
2020-04-06T11:58:10.924613120Z
2020-04-06T11:58:10.924659485Z initdb: warning: enabling "trust" authentication for local connections
2020-04-06T11:58:10.924720453Z You can change this by editing pg_hba.conf or using the option -A, or
2020-04-06T11:58:10.924753751Z --auth-local and --auth-host, the next time you run initdb.
2020-04-06T11:58:10.925150488Z
2020-04-06T11:58:10.925175359Z Success. You can now start the database server using:
2020-04-06T11:58:10.925182577Z
2020-04-06T11:58:10.925188661Z pg_ctl -D /var/lib/postgresql/data -l logfile start
2020-04-06T11:58:10.925195041Z
2020-04-06T11:58:10.974712774Z waiting for server to start....2020-04-06 11:58:10.974 UTC [47] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-04-06T11:58:10.976267115Z 2020-04-06 11:58:10.976 UTC [47] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-04-06T11:58:11.003287980Z 2020-04-06 11:58:11.002 UTC [48] LOG: database system was shut down at 2020-04-06 11:58:10 UTC
2020-04-06T11:58:11.011056242Z 2020-04-06 11:58:11.010 UTC [47] LOG: database system is ready to accept connections
2020-04-06T11:58:11.051536096Z done
2020-04-06T11:58:11.051578164Z server started
2020-04-06T11:58:11.051855017Z
2020-04-06T11:58:11.052088262Z /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
2020-04-06T11:58:11.218053189Z psql: error: could not connect to server: could not translate host name "postgres" to address: Name or service not known
could not translate host name "postgres" to address: Name or service not known
It seems to me that the host "postgres" is wrong. But the documenation of GitLab says that the hostname will be the alias: https://docs.gitlab.com/ce/ci/docker/using_docker_images.html#accessing-the-services
Excerpt of my .gitlab-ci-yml:
image: node:lts-stretch
services:
- name: redis:latest
- name: postgis/postgis:latest
alias: postgres
variables:
NODE_ENV: production
REDIS_HOST: redis
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGHOST: postgres
PGUSER: postgres
PGPASSWORD: postgres
I have also tried to remove the alias and use "postgis-postgis" or "postgis__postgis" as the hostname as per documenation, but the same error every time. I also tried to use the docker image "mdillon/postgis" because i saw it often, but also the same error.

I tried plugging in your .gitlab-ci.yml excerpt and got an error:
This GitLab CI configuration is invalid: jobs config should contain at least one visible job
Please provide a minimal reproducible example next time. ;)
I was able to reproduce and fix the issue. The fix was to remove the PGHOST setting. (You had its value set to postgres. Your main container can get to the postgis container using the alias postgres but the postgis container itself doesn't need a hostname to get to the PostgreSQL service because that service is listening on a local socket.)
PGHOST is used by psql in the "postgis" container (launched by the services directive), in the script https://github.com/postgis/docker-postgis/blob/master/initdb-postgis.sh (which ends up in /docker-entrypoint-initdb.d/10_postgis.sh -- see https://github.com/postgis/docker-postgis/blob/master/Dockerfile.template#L16)
The following .gitlab-ci.yml works:
image: node:lts-stretch
variables:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGUSER: postgres
PGPASSWORD: postgres
services:
- name: postgis/postgis:latest
alias: postgres
job1:
script: ping -c 3 postgres
Here is the job log:
Running with gitlab-runner 12.9.0 (4c96e5ad)
on docker-auto-scale 0277ea0f
Preparing the "docker+machine" executor
Using Docker executor with image node:lts-stretch ...
Starting service postgis/postgis:latest ...
Pulling docker image postgis/postgis:latest ...
Using docker image sha256:a412dcb70af7acfbe875faea4467a1594e7cba3dfca19e5e1c6bcf35286380df for postgis/postgis:latest ...
Waiting for services to be up and running...
Pulling docker image node:lts-stretch ...
Using docker image sha256:88c089733a3b980b3517e8e2e8afa46b338f69d7562550cb3c2e9fd852a2fbac for node:lts-stretch ...
Preparing environment
00:05
Running on runner-0277ea0f-project-17971942-concurrent-0 via runner-0277ea0f-srm-1586221223-45d7ab06...
Getting source from Git repository
00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/atsaloli/service-postgis/.git/
Created fresh repository.
From https://gitlab.com/atsaloli/service-postgis
* [new ref] refs/pipelines/133464596 -> refs/pipelines/133464596
* [new branch] master -> origin/master
Checking out d20469e6 as master...
Skipping Git submodules setup
Restoring cache
00:02
Downloading artifacts
00:01
Running before_script and script
00:04
$ ping -c 3 postgres
PING postgres (172.17.0.3) 56(84) bytes of data.
64 bytes from postgis-postgis (172.17.0.3): icmp_seq=1 ttl=64 time=0.077 ms
64 bytes from postgis-postgis (172.17.0.3): icmp_seq=2 ttl=64 time=0.064 ms
64 bytes from postgis-postgis (172.17.0.3): icmp_seq=3 ttl=64 time=0.060 ms
--- postgres ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2062ms
rtt min/avg/max/mdev = 0.060/0.067/0.077/0.007 ms
Running after_script
00:01
Saving cache
00:02
Uploading artifacts for successful job
00:01
Job succeeded
As you can see in the ping command above, the container created from the image node:lts-stretch is able to access the postgis container using the postgres alias.
Does that unblock you?

Related

Connect the Cassandra container to application web container failed - Error: 202 Connecting to Node

So, I created two docker's images and I want to connect one to which other with the docker composer. The first image is Cassandra 3.11.11 (from the official hub docker) and the other I created by myself with the tomcat version 9.0.54 and my application spring boot.
I ran the docker-compose.ylm below to connect the two container, where cassandra:latest is the cassandra's image and centos7-tomcat9-myapp is my app web's image.
version: '3'
services:
casandra:
image: cassandra:latest
myapp:
image: centos7-tomcat9-myapp
depends_on:
- casandra
environment:
- CASSANDRA_HOST=cassandra
I ran the command line to start the app web's image : docker run -it --rm --name fe3c2f120e01 -p 8888:8080 centos7-tomcat9-app .
In the console log the spring boot show me the error below. It happened, because the myapp's container could not connect to the Cassandra's container.
2021-10-15 15:12:14.240 WARN 1 --- [ s0-admin-1]
c.d.o.d.i.c.control.ControlConnection : [s0] Error connecting to
Node(endPoint=127.0.0.1:9042, hostId=null, hashCode=47889c49), trying
next node (ConnectionInitException: [s0|control|connecting...]
Protocol initialization request, step 1 (OPTIONS): failed to send
request (io.netty.channel.StacklessClosedChannelException))
What am I doing wrong?
EDIT
This is the nodetool status about the cassandra's image:
[root#GDBDEV04 cassandradb]# docker exec 552d359d177e nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.18.0.3 84.76 KiB 16 100.0% 685b6e0a-13c2-4d41-ba99-f3b0fa94477c rack1
EDIT 2
I need to connect the Cassandra's DB image with the web application image. It is different to connect microservices. I tried to change the 127.0.0.0 (inside the cassandra.yaml) to 0.0.0.0 (only to test) and the error persist. I think something missing in my docker-compose.yml for sure. However, I did not know what.
Finally I found the error. In my case, I need to fixed the docker-compose.yml file adding the Cassandra and Tomcat's ports. And in my application.properties (spring boot config file), I changed the cluster's name.
Docker-compose.yml:
version: '3'
services:
cassandra:
image: cassandra:latest
ports:
- "9044:9042"
myapp:
image: centos7-tomcat9-myapp
ports:
-"8086:8080"
depends_on:
- cassandra
environment:
- CASSANDRA_HOST=cassandra
Application.config :
# CASSANDRA (CassandraProperties)
cassandra.cluster = Test Cluster
cassandra.contactpoints=${CASSANDRA_HOST}
This question help me to resolve my problem: Accessing docker container mysql databases

Start a Maridb service in GitLab CI failed

I tried to add a mariadb service in GitLab CI for running tests.
Define the docker vars in gobal variables and add a mariadb in the job test/services.
variables:
MYSQL_DATABASE: backend
MYSQL_USER: admin
MYSQL_PASSWORD: admin
test:
stage: test
image: maven:3.6.3-openjdk-16
services:
- name: mariadb
alias: db
command: [ "--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci" ]
...
When the codes are pushed to GitLab.com.
And I saw the following logs.
Starting service mariadb:latest ...
Pulling docker image mariadb:latest ...
Using docker image sha256:e76a4b2ed1b4014a9d638e15cd852544d8171c64ed78096fbe6e5a108fbf20b0 for mariadb:latest with digest mariadb#sha256:9c681cefe72e257c6d58f839bb504f50bf259a0221c883fcc220f0755563fa46 ...
Waiting for services to be up and running...
*** WARNING: Service runner-fa6cab46-project-18612327-concurrent-0-0fddafc5b30beaaa-mariadb-0 probably didn't start properly.
Health check error:
start service container: Error response from daemon: Cannot link to a non running container: /runner-fa6cab46-project-18612327-concurrent-0-0fddafc5b30beaaa-mariadb-0 AS /runner-fa6cab46-project-18612327-concurrent-0-0fddafc5b30beaaa-mariadb-0-wait-for-service/service (docker.go:1156:0s)
Service container logs:
2021-04-13T08:30:50.821859467Z 2021-04-13 08:30:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.9+maria~focal started.
2021-04-13T08:30:50.920686916Z 2021-04-13 08:30:50+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
2021-04-13T08:30:50.920714063Z command was: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --verbose --help --log-bin-index=/tmp/tmp.Kzx9BNn0Bl --encrypt-tmp-files=0
2021-04-13T08:30:50.920720617Z mysqld: Character set 'utf8mb4 --collation-server=utf8mb4_unicode_ci' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
2021-04-13T08:30:50.920875405Z mysqld: Character set 'utf8mb4 --collation-server=utf8mb4_unicode_ci' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
But I ran a mariadb instance in my docker container, it is working well, not seen such info.

Included container does't work with docker compose

I have Kafka/Zookeeper container and Divolte container in - https://github.com/divolte/docker-divolte/blob/master/docker-compose.yml, which correctly starts and works by
docker-compose up -d --build
I want to add the hdfs container - https://hub.docker.com/r/mdouchement/hdfs/ which correctly starts and works by
docker run -p 22022:22 -p 8020:8020 -p 50010:50010 -p 50020:50020 -p 50070:50070 -p 50075:50075 -it mdouchement/hdfs
But after adding the code to yml:
hdfs:
image: mdouchement/hdfs
environment:
DIVOLTE_KAFKA_BROKER_LIST: kafka:9092
ports:
- "22022:22"
- "8020:8020"
- "50010:50010"
- "50020:50020"
- "50070:50070"
- "50075:50075"
depends_on:
- kafka
The web http://localhost:50070 and data node http://localhost:8020/ did not answer. Could you help me to add new container? Which of hdfs ports do I have to write as source connection port?
The logs of HDFS container is:
2020-02-21T15:11:47.613270635Z Starting OpenBSD Secure Shell server: sshd.
2020-02-21T15:11:50.440130986Z Starting namenodes on [localhost]
2020-02-21T15:11:54.616344960Z localhost: Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
2020-02-21T15:11:54.616369660Z localhost: starting namenode, logging to /opt/hadoop/logs/hadoop-root-namenode-278b399bc998.out
2020-02-21T15:11:59.328993612Z localhost: Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
2020-02-21T15:11:59.329016212Z localhost: starting datanode, logging to /opt/hadoop/logs/hadoop-root-datanode-278b399bc998.out
2020-02-21T15:12:06.078269195Z Starting secondary namenodes [0.0.0.0]
2020-02-21T15:12:10.837364362Z 0.0.0.0: Warning: Permanently added '0.0.0.0' (ECDSA) to the list of known hosts.
2020-02-21T15:12:10.839375064Z 0.0.0.0: starting secondarynamenode, logging to /opt/hadoop/logs/hadoop-root-secondarynamenode-278b399bc998.out
2020-02-21T15:12:17.249040842Z starting portmap, logging to /opt/hadoop/logs/hadoop--portmap-278b399bc998.out
2020-02-21T15:12:18.253954832Z DEPRECATED: Use of this script to execute hdfs command is deprecated.
2020-02-21T15:12:18.253993233Z Instead use the hdfs command for it.
2020-02-21T15:12:18.254002633Z
2020-02-21T15:12:21.277829129Z starting nfs3, logging to /opt/hadoop/logs/hadoop--nfs3-278b399bc998.out
2020-02-21T15:12:22.284864146Z DEPRECATED: Use of this script to execute hdfs command is deprecated.
2020-02-21T15:12:22.284883446Z Instead use the hdfs command for it.
2020-02-21T15:12:22.284887146Z
Port description:
Ports
Portmap -> 111
NFS -> 2049
HDFS namenode -> 8020 (hdfs://localhost:8020)
HDFS datanode -> 50010
HDFS datanode (ipc) -> 50020
HDFS Web browser -> 50070
HDFS datanode (http) -> 50075
HDFS secondary namenode -> 50090
SSH -> 22
The docker-compose response answer is:
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
divolte-streamsets-quickstart_divolte_1 /opt/divolte/start.sh Up 0.0.0.0:8290->8290/tcp
divolte-streamsets-quickstart_hdfs_1 /bin/sh -c service ssh sta ... Exit 0
divolte-streamsets-quickstart_kafka_1 supervisord -n Up 2181/tcp, 9092/tcp, 9093/tcp, 9094/tcp, 9095/tcp, 9096/tcp, 9097/tcp, 9098/tcp, 9099/tcp
divolte-streamsets-quickstart_streamsets_1 /docker-entrypoint.sh dc -exec Up 0.0.0.0:18630->18630/tcp

Spring Boot tries to connect to Mongo localhost

I have a Spring Boot 2.x project using Mongo. I am running this via Docker (using compose locally) and Kubernetes. I am trying to connect my service to a Mongo server. This is confusing to me, but for development I am using a local instance of Mongo, but deployed in GCP I have named mongo services.
here is my application.properties file:
#mongodb
spring.data.mongodb.uri= mongodb://mongo-serviceone:27017/serviceone
#logging
logging.level.org.springframework.data=trace
logging.level.=trace
And my Docker-compose:
version: '3'
# Define the services/containers to be run
services:
service: #name of your service
build: ./ # specify the directory of the Dockerfile
ports:
- "3009:3009" #specify ports forwarding
links:
- mongo-serviceone # link this service to the database service
volumes:
- .:/usr/src/app
depends_on:
- mongo-serviceone
mongo-serviceone: # name of the service
image: mongo
volumes:
- ./data:/data/db
ports:
- "27017:27017"
When I try docker-compose up . I get the following error:
mongo-serviceone_1 | 2018-08-22T13:50:33.454+0000 I NETWORK
[initandlisten] waiting for connections on port 27017 service_1
| 2018-08-22 13:50:33.526 INFO 1 --- [localhost:27017]
org.mongodb.driver.cluster : Exception in monitor thread
while connecting to server localhost:27017 service_1
| service_1 | com.mongodb.MongoSocketOpenException:
Exception opening socket service_1 | at
com.mongodb.connection.SocketStream.open(SocketStream.java:62)
~[mongodb-driver-core-3.6.3.jar!/:na]
running docker ps shows me:
692ebb72cf30 serviceone_service "java -Djava.securit…" About an hour ago Up 9 minutes 0.0.0.0:3009->3009/tcp, 8080/tcp serviceone_service_1
6cd55ae7bb77 mongo "docker-entrypoint.s…" About an hour ago Up 9 minutes 0.0.0.0:27017->27017/tcp serviceone_mongo-serviceone_1
While I am trying to connect to a local mongo, I thought that by using the name "mongo-serviceone"
Hard to tell what the exact issue is, but maybe this is just an issue because of the space " " after "spring.data.mongodb.uri=" and before "mongodb://mongo-serviceone:27017/serviceone"?
If not, maybe exec into the "service" container and try to ping the mongodb with: ping mongo-serviceone:27017
Let me know the output of this, so I can help you analyze and fix this issue.
Alternatively, you could switch from using docker compose to a Kubernetes native dev tool, as you are planning to run your application on Kubernetes anyways. Here is a list of possible tools:
Allow hot reloading:
DevSpace: https://github.com/covexo/devspace
ksync: https://github.com/vapor-ware/ksync
Pure CI/CD tools for dev:
Skaffold: https://github.com/GoogleContainerTools/skaffold
Draft: https://github.com/Azure/draft
For most of them, you will only need minikube or a dev namespace inside your existing cluster on GCP.
Looks like another application was running on port 27017 on your localhost Similar reported issue
quick way to check on linux/mac:
telnet 127.0.01 27017
check logs files:
docker logs serviceone_service

how to make ansible get access to an sshd container?

I use an ansible script to load & start the https://hub.docker.com/r/rastasheep/ubuntu-sshd/ container.
so it starts well of course :
bash-4.4$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8bedbd3b7d88 rastasheep/ubuntu-sshd "/usr/sbin/sshd -D" 37 minutes ago Up 36 minutes 0.0.0.0:49154->22/tcp test
bash-4.4$
so after ansible failure on ssh access to it I tested manually from shell
this is also ok.
bash-4.4$ ssh root#172.17.0.2
The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
ECDSA key fingerprint is SHA256:YtTfuoRRR5qStSVA5UuznGamA/dvf+djbIT6Y48IYD0.
ECDSA key fingerprint is MD5:43:3f:41:e9:89:45:06:6f:f6:42:c4:6a:70:37:f8:1d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.2' (ECDSA) to the list of known hosts.
root#172.17.0.2's password:
root#8bedbd3b7d88:~# logout
Connection to 172.17.0.2 closed.
bash-4.4$
so the step that failed is trying to get on it from ansible script & make access to ssh-copy-id
ansible error message is :
Fatal: [172.17.0.2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '172.17.0.2' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey,password).\r\n", "unreachable": true}
---
- hosts: 127.0.0.1
tasks:
- name: start docker service
service:
name: docker
state: started
- name: load and start the container we wanna use
docker_container:
name: test
image: rastasheep/ubuntu-sshd
state: started
ports:
- "49154:22"
- name: Wait maximum of 300 seconds for ports to be available
wait_for:
host: 0.0.0.0
port: 49154
state: started
- hosts: 172.17.0.2
vars:
passwordadmin: $6$pbE6yznA$AeFIdI.....K0
passwordroot: $6$TMrxQUxT$I8.JIzR.....TV1
ansible_ssh_extra_args: "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
tasks:
- name: Build test container root user rsa ssh-key
shell: docker exec test ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
so I cannot even run the needed step to build ssh
how to do then ??
1st step (ansible task) : load docker container
2cd step (ansible task on only 172.17.0.2) : connect to it & setup it
there will be 3rd step to run application on it after that.
the problem occurs only when starting the 2cd step
Ok after many trys on a second container
conclusion is my procedure was bad
what I have done to solve that :
build a diroctory tree separating ./ ./inventory ./includes
build 1 yaml file by host (local, docker, labo)
build 1 main yaml file on ./
build 1 new host file in ./inventory
connect forced by sshpass to docker on default password
changed it
add the host key on authorized key to a login dedicated usage
installed pyhton (needed to answer ansible host else it makes
randomly module errors or refused connections depending on current
action)
setup a ssh login user in sudoers
then I can un the docker.yaml actions
then only at last I can run the labo.yaml actions.
Thanks for help
now I'm able to build the missing tools.

Resources