GitLab-CE installation using Docker-Compose file - Ssh git user asking password - docker-compose

I have successfully installed GitLab-CE edition using Docker-Compose file as per below link on my Docker host server.
https://docs.gitlab.com/omnibus/docker/#install-gitlab-using-docker-compose
My docker-compose.yml content as follows.
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.example.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2223
ports:
- '80:80'
- '443:443'
- '2223:22'
volumes:
- '$GITLAB_HOME/gitlab/config:/etc/gitlab'
- '$GITLAB_HOME/gitlab/logs:/var/log/gitlab'
- '$GITLAB_HOME/gitlab/data:/var/opt/gitlab'
In one of my Ubuntu client system when I run ssh -T -p 2223 git#gitlab.example.com it works (It shows Welcome to GitLab). Whereas in my docker host if I remove the following - gitlab_rails['gitlab_shell_ssh_port'] = 2223 in my gitlab.rb file after running gitlab-ctl reconfigure. Again if i run ssh -T git#gitlab.example.com it is asking git user's password.
Docker-Server's 22 port listening as below.
netstat -tulnp | grep :22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1516/sshd
tcp6 0 0 :::2222 :::* LISTEN 2587/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 1516/sshd
Since sshd service is already running on 22 port on my docker server, So is there any way to use 22 default port to clone our GitLab repository? Without changing sshd default port. Like below example command i would want to clone. So any suggestion would be helpful.
git clone git#gitlab.example.com:sample-group/sample.git
#Exadra37, i have updated the data you shared and tried to rebuild, but it fails.
[root#gitlab]# docker-compose up --build
WARNING: The SSH_AUTH_SOCK variable is not set. Defaulting to a blank string.
Recreating 486bb3cb8496_docker-gitlab-ce_web_1 ... error
ERROR: for 486bb3cb8496_docker-gitlab-ce_web_1 Cannot create container for service web: create .: volume name is too short, names should be at least two alphanumeric characters
ERROR: for web Cannot create container for service web: create .: volume name is too short, names should be at least two alphanumeric characters
ERROR: Encountered errors while bringing up the project.

You need to map your ssh socket into the container.
Add the following to your docker-compose.yml file:
environment:
- SSH_AUTH_SOCK=/ssh-agent
volumes:
- $SSH_AUTH_SOCK:/ssh-agent

Related

unsupported port number: 0

If we specify single port in dockerfile or docker-compose file like below
sshd:
build: ./backend/mock/sshd
volumes:
- ./docker/sftp_upload_dir:/root/upload_dir
ports:
- '22'. #<----------
and use the docker-compose file with nerdctl using command
nerdctl compose up
then nerdctl command will exit with following error
FATA[0000] unsupported port number: 0
As per docker documentation https://docs.docker.com/compose/compose-file/compose-file-v3/#ports
There are three options:
Specify both ports (HOST:CONTAINER)
Specify just the container port (an ephemeral host port is chosen for the host port).
Thus 0 is chosen as the host port which creates error, so solution is to explicitly specify host port as below
sshd:
build: ./backend/mock/sshd
volumes:
- ./docker/sftp_upload_dir:/root/upload_dir
ports:
- '22:22' #<<<<---------
Note that I have explicitly added 22: before 22 in the last line to make it work with nerdctl. It works by default with docker-compose up.

Can't connect to DB located in docker container

I'm trying to create PostgreSQL DB inside docker container and connect to it from my local machine. Running docker-compose up -d with that inside docker-compose.yml:
version: '3.5'
services:
db:
image: postgres:12.2
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_DB: db
POSTGRES_USER: root
POSTGRES_PASSWORD: root
ended successfully. No crashes, errors of something. But, when I'm trying to connect to it with pgAdmin4 with these credentials:
Host name/address: localhost
Port: 5432
Maintenance database: db
Username: root
Password: root
it says to me:
Unable to connect to server:
FATAL: password authentication failed for user "root"
My OS: Windows 10 build(1809)
PostgreSQL version (installed on local machine): 12
Docker version: 19.03.13, build 4484c46d9d
UPD 1:
After re-creating container with different ports (now it is 5433:5433), pgAdmin4 error changed:
Unable to connect to server:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Host name/address: localhost
Port: 5432
You are trying to connect to 5432 port on localhost. Are you sure your container is taking the host IP?
To make the container run with the host IP run the container with --network host option.
docker run --network host <rest of the command>
Note that if you use '--network host' option, then portmapping '-p' option is not needed.
Read https://docs.docker.com/network/host/ for more information.
Have you checked you've cleaned away any old instances running locally and that you're not trying to access an old instance?
You can wipe out all local docker containers with: docker rm -f $(docker ps -aq)
Once you've got a clean environment you can try spin up the containers again locally and see if you can access the service. I copy/pasted what you have into a clean docker-compose.yaml and ran docker-compose up against the file - it worked and I logged in and was able to view the pg_user table.
If it still fails you can try to find the IP using: netstat -in | grep en0 which will show something like
en0 1500 192.168.1 **192.168.1.163** 15301832 - 9001208 - - -
this shows the external/accessible IP of the container. Try using the address shown (something similar to 192.168.1.163) instead of localhost

Can't connect to postgres db from pgadmin (both running on docker)?

I'm running postgres and pgadmin4 on docker with docker-compose up on a fedora 28 OS and I'm having trouble creating a new db server from pgadmin's web console.
This is the docker-compose.yml file I'm using.
version: '3.0'
services:
db:
image: postgres:9.6
ports:
- 5432:5432/tcp
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin
- POSTGRES_DB=mydb
pgadmin:
image: dpage/pgadmin4
ports:
- 5454:5454/tcp
environment:
- PGADMIN_DEFAULT_EMAIL=admin#mydomain.com
- PGADMIN_DEFAULT_PASSWORD=postgres
- PGADMIN_LISTEN_PORT=5454
What should I write in the Create new server > Connection tab > "Host name/address" field? If I type in localhost or 127.0.0.1 I get an error (Unable to connect, see screenshot1 and screenshot2). If I type db (the service's name as specified in the yml file), only then pgadmin accepts it and creates a db server with a postgres database called mydb.
Why? How do I find the ip that goes in the address field?
Furthermore, on Fedora28:
$ netstat -napt | grep LIST
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN -
tcp6 0 0 :::5454 :::* LISTEN -
tcp6 0 0 ::1:631 :::* LISTEN -
tcp6 0 0 :::5432 :::* LISTEN -
$
I encountered this problem just recently too. There are two approaches I found:
1) See here. Basically, you just search for the IP address of the postgres container and use that IP address in pgadmin4:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
194d4a5f9dd0 dpage/pgadmin4 "/entrypoint.sh" 48 minutes ago Up 48 minutes 443/tcp, 0.0.0.0:8080->80/tcp docker-postgis_pgadmin_1
334d5bdc87f7 kartoza/postgis:11.0-2.5 "/bin/sh -c /docke..." 48 minutes ago Up 48 minutes (healthy) 0.0.0.0:5432->5432/tcp docker-postgis_db_1
In my case, the postgres container ID is 334d5bdc87f7. Then look for the IP address:
$ docker inspect 334d5bdc87f7 | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "172.18.0.2",
When I used 172.18.0.2 in pgadmin4, I connected to the database! Yey!
2) The 2nd approach is easier. Instead of using localhost or 127.0.0.1 or ::1, I used my IP address in my local network (e.g. in your case 192.168.122.1?). Afterwards, I connected to the postgres container!
From my reading of the docs and testing this myself you're doing it right using the database service name from the docker-compose yml file as the "Host name/address" field value in pgAdmin.
https://docs.docker.com/compose/networking/
In your "pgadmin" section I would use port values of 8080 or 80, why 5454?

Could not connect to Postgres from Symfony 4 + Docker

I run into the strange problem. I've created docker-compose file to build php + nginx + postgres services:
version: '2'
services:
db:
image: orchardup/postgresql
ports:
- "5433:5432"
environment:
LC_ALL: C.UTF-8
POSTGRESQL_USER: postgres
POSTGRESQL_DB: db
POSTGRESQL_PASS: postgres
php:
build: .docker/php-fpm
ports:
- "9002:9002"
volumes:
- .:/var/www/symfony:cached
- ./var/log/symfony:/var/www/symfony/var/log:cached
links:
- db
nginx:
build: .docker/nginx
ports:
- "8001:80"
links:
- php
volumes_from:
- php
volumes:
- ./var/log/nginx/:/var/log/nginx:cached
After that I created DB schema by running bin/console doctrine:schema:update --force . The tables and migrations created just fine. Seems like DB connection is ok. I checked this by connecting to db from my machine through psql with credentials from .env, the tables are there.
But when I go to the web page and trying to authorize, I get an error told me the connection is not ok:
Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5433?"
I checked in both case I have dev environment - from the web page and from the console. I tried 5433 and 5432 ports with no success. I tried everything I could find for 3 hours.
This is the output from the postgres container:
# netstat -tlpn | grep 5432
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 12/postgres
tcp6 0 0 :::5432 :::* LISTEN 12/postgres
# grep listen /etc/postgresql/9.3/main/postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
The only way for containers to talk to each other is through IPs. By linking multiple containers together through --link (or links in docker-compose), docker creates a secure tunnel between those two containers so that we don't need to expose any ports externally.
If you try to connect to your database from your local environment through a database client, you will be able to connect to it from 127.0.0.1:5433 as the port is exposed to your host through the docker-compose file. This is the reason why your schema update command succeeded.
Docker exposes connectivity information for the source container to
the recipient container in two ways:
Environment variables,
Updating the /etc/hosts file.
Ref: https://docs.docker.com/network/links/#communication-across-links
In order to connect to your database (which is running in the db container) from the php container, you will need to get the host of your db container through the environment variable DB_PORT_5432_TCP_ADDR (I might be wrong on this, but type env in your php container's terminal to verify. You will need to SSH into your php container).
Alternatively, you can use the second method, which is just db as the hostname instead of 127.0.0.1 since docker updated the /etc/hosts file in the php container to map your linked container's name to its IP, and in this case, the value mapped to the hostname db is the same as the value stored in the environment variable DB_PORT_5432_TCP_ADDR.

Using Docker to launch web app, can't connect to Postgresql DB?

I received the following error when trying to write session data using Tomcat's PersistentManager to a Postgres DB running on my local machine:
SEVERE: A SQL exception occurred 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.
The application itself runs in a docker container. For completeness sake, my current context.xml file is:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Manager className="org.apache.catalina.session.PersistentManager"
distributable="true" processExpiresFrequency="6" maxIdleBackup="0" debug="99" >
<Store className="org.apache.catalina.session.JDBCStore"
driverName="org.postgresql.Driver"
connectionURL="jdbc:postgresql://localhost/admin?stringtype=unspecified"
connectionName="admin" connectionPassword="admin"
sessionAppCol="app_name" sessionDataCol="session_data" sessionIdCol="session_id"
sessionLastAccessedCol="last_access" sessionMaxInactiveCol="max_inactive"
sessionTable="tomcat_sessions_tb" sessionValidCol="valid_session" />
</Manager>
</Context>
Pursuant to the suggestions here: Postgresql : Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections
I confirmed via a netstat -aln | grep LISTEN that Postgresql is running and listening on the correct ports:
tcp4 0 0 127.0.0.1.5432 *.* LISTEN
tcp6 0 0 ::1.5432 *.* LISTEN
and that my postgresql.conf (located in usr/local/var/postgres) has listen_addresses = localhost and port = 5432, which mirrors the host and port of my running server in Pgadmin3.
I suspect that the problem is that Docker runs in a VM, and thus the local information I have obtained may not be the whole story. Reading up on the available information online, it seems that I may require some sort of bridged networking.
However, I admit I am a novice in this area, and I'm unsure of how to set it up.
Why I can NOT connect to localhost:5432?
Cat your container's /etc/hosts
$ sudo docker exec -it [container] cat /etc/hosts
For docker networks is bridge by default, the localhost inside points to container itself(Docker default bridge network).
Then you don't have 5432 listening in your container:
$ sudo docker exec [container] nc -v -z localhost 5432
Solution 1. If you wanna hardcode the "localhost:5432" inside your config xml, the easiest way is creating your container with the option "--net=host":
$ sudo docker run --net=host -it ...
Solution 2. Change the localhost of your docker host ip inside the container
Get your docker host ip:
$ sudo docker inspect -f '{{ .NetworkSettings.Gateway }}'
192.168.5.1
Enter your container:
$ sudo docker exec -it [container] /bin/bash
Edit the file /etc/hosts to point the localhost to docker host ip:
$ sudo vim /etc/hosts
192.168.5.1 localhost
Solution 3. Modify your db config file to use an alias instead of localhost:
connectionURL="jdbc:postgresql://DB_ALIAS/admin?stringtype=unspecified"
Then add the DB_ALIAS to the container's hosts :
$ sudo docker run --add-host DB_ALIAS:192.168.5.1 -it [image] ...
If you are using docker-compose together with postgres image, than you can reuse service name as IP inside jdbc connection (here: app-db)
web:
build: ./web
ports:
- "8080:8080"
links:
- app-db
environment:
- MYAPP_JDBC_URL=jdbc:postgresql://app-db:5432/somedb
- MYAPP_JDBC_USER=someuser
- MYAPP_JDBC_PASS=pass
app-db:
image: postgres:9.6
environment:
- POSTGRES_USER=someuser
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=somedb
expose:
- 5432
volumes_from:
- app-db-data
app-db-data:
image: cogniteev/echo
command: echo 'Data Container for PostgreSQL'
volumes:
- /opt/postgresdata/:/var/lib/postgresql/data
The best decision!
jdbc:postgresql://host.docker.internal:5432/somedb
Don't thank.
I had to expose port with -p 5432:5432:
docker run --name postgres -e POSTGRES_PASSWORD=secret -d -p 5432:5432 postgres
I was getting the same error but this simple solution works perfect for me.
sudo docker run -d --net="host" -it <IMAGE>
Now I can run my app https://x.x.x.x:pppp/../.. and everything works fine. I hope this helps