Links working with `docker-compose` but not `docker compose` - docker

I have been using a docker compose file to run a development environment for a microservices architecture that in production is deployed to kubernetes, so I use links to map k8s provided domain names to the compose service names. e.g
links:
- "kafka:kafkadc-c44b-44.default.svc.cluster.local"
All works well when using docker-compose. But when using the new docker compose (note no hyphen), the containers are unable to comminicate with eachother. Kafka connections fail. HTTP requests fail.
Are there any changes between the docker cli version of compose, and the old docker-compose command. I cann't see a version of docker compose without the hypen, but with I have the following version information:
docker-compose version 1.29.0, build 07737305
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h 22 Sep 2020

You can use hostname to specify a hostname for the container within its network or you can use an alias if you need a hostname per network.
e.g.
db:
image: mysql:5.7
container_name: mycontainername
hostname: myhostname
networks:
default:
aliases:
myalias

Related

Docker compose breaks ssh connection

I am trying to run a few docker containers on GCP VMs. As of today, when I run a docker-compose, my ssh connection breaks. This was not happening as of this morning. The only thing that changed was I did a sudo apt update && sudo apt upgrade.
An example of a docker-compose file that breaks the connection:
version: '3'
services:
mongo:
container_name: mongo
image: mongo
expose:
- "27017"
ports:
- "27017:27017"
I'm on Ubuntu 5.13.0-1030-gcp #36~20.04.1-Ubuntu SMP Fri Jun 3 15:33:42 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux.
docker-compose version 1.25.0
Docker version 20.10.17, build 100c701
and I'm using BuildKit for my Docker and docker-compose builds.
I'm not sure how to debug this issue, any suggestions would be appreciated. Will update the post with more info if needed.
Check your dmesg to see if the kernel crashed.
Probably related to https://www.mail-archive.com/kernel-packages#lists.launchpad.net/msg482001.html
in our case it was an internal ip address space exhaustion
because docker switches afterwards to the 192.168.. network
and blocks external traffic
to fix - shutdown all docker containers
purge all docker networks
add or append to docker daemon.json
e.g. vi /etc/docker/daemon.json for 512 networks
{
"default-address-pools":[
{"base":"172.20.0.0/16","size":24},
{"base":"172.21.0.0/16","size":24}
]
}
Do not update your kernel,new kernel will influence docker process

Gitlab CI runner fails at docker-compose build with profiles

My idea is to have a single docker-compose file that I can configure with --profile db_as_container flag depending on whether I want to have cloud database (MongoDB atlas) or local database-as-container.
Here's my docker-compose.yml:
version: '3'
services:
app:
image: '${APP_NAME}:${TAG:-latest}'
build: .
ports:
- '${PORT}:${PORT}'
mongo_db:
image: mongo
container_name: mongo_db_container
ports:
- "27017:27017"
profiles:
- db_as_container
My docker compose up shell script (dc-up.sh) deduces whether my DB_CONNECTION_STRING is cloud type or local container type and calls appropriate up command.
TAG=${TAG} docker-compose --profile db_as_container up -d --build
vs.
TAG=${TAG} docker-compose up -d --build
And this works locally and does not complain about using profiles.
Problem is when my Gitlab CI runner runs my build script (build-and-push.sh):
TAG=${TAG} docker-compose build
It produces this error:
The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.mongo_db: 'profiles'
What am I doing wrong here?
Actually the issue was not the version of the compose file specification, but rather docker-compose itself as i've found out here
Support for service profiles was added in docker-compose version 1.28
Updating from 1.262 to 1.28.6 solved my issue.
Only Docker Compose v3 has profiles option. I'm guessing your CI compose version is a lower one.
You will need to upgrade it to version 3.

docker-compose up doesn't map ports on centos 7

I'm trying to docker-compose an existing application. Now I struggle on centos on a basic task.
Given docker-compose.yml:
version: '3.8'
services:
nginx:
image: nginx:latest
ports:
- "1024:80"
When run with docker-compose up localhost:1024 is not accessible. When I add the started container to the default bridge network (docker network connect <id of bridge> <id of container>), localhost:1024 is accessible.
When run with docker run -p 1024:80 nginx:latest localhost:1024 is accessible.
docker-compose version 1.26.2, build eefe0d31
Docker version 19.03.12, build 48a66213fe
CentOS Linux release 7.6.1810
When attempting to docker-compose up the same file on macOS localhost:1024 is accessible.
EDIT #1
docker ps PORTS output: 0.0.0.0:1024->80/tcp
new interface added ifconfig: br-da0abb61196d
Same behavior on different ports e.g. 8080

docker stack ignoring unsupported options

I am running docker Server Version: 18.06.0-ce on centos 7.5.
I have a docker-compose file running db2 server with the following sample definition:
The docker-compose file has the following options:
version: "3.7"
services:
db2exp:
image: db2
ports:
- "50000:50000"
networks:
- lmnet
ipc: host
cap_add:
- IPC_LOCK
- IPC_OWNER
environment:
- DB2INSTANCE=db2inst1
- DB2PASSWD=db2inst1
- LICENSE=accept
volumes:
- db2data:/home
When using docker-compose up, I do not have problems with starting the db2 service. However when I try to use docker stack, I get the following message:
docker stack deploy test --compose-file docker-compose.yml
Ignoring unsupported options: cap_add, ipc
This renders db2start to return SQL1042C An unexpected system error occurred.
It would be ideal if what runs in compose runs in stack. What, if any, can be done so that the db2 container can be used in a docker stack environment and not just docker-compose?
If it matters, I have docker-compose version 1.23.0-rc1, build 320e4819.
Thanks in advance.
This is not supported by swarm mode currently as the error message you've show and documentation identify. Personally I'd question whether you really want to have your database running in swarm mode. Docker does not migrate the volume for you, so you wouldn't see your data if rescheduled on another node.
You can follow the progress of getting this added to Swarm Mode in the github issues, there are several, including:
https://github.com/moby/moby/issues/24862
https://github.com/moby/moby/issues/25885
The hacky solution I've seen if you really need this run from swarm mode is to schedule a container with the docker socket mounted and docker binaries in the image, which then executes a docker run command directly against the local engine. E.g.:
version: "3.7"
services:
db2exp-wrapper:
image: docker:stable
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: docker run --rm --cap-add IPC_LOCK --cap-add IPC_OWNER -p 50000:50000 ... db2
I don't really recommend the above solution, sticking with docker-compose would likely be a better implementation for your use case. Downsides of this solution include only publishing the port on the single host, and potential security risks of anyone else with access to that docker socket.

docker swarm with compose file does not recognize "links"

docker-compose.yml
version: '3.3'
services:
hello:
image: dockercloud/hello-world
service_auth:
image: beevelop/nginx-basic-auth
ports:
- 8080:80
links:
- hello:web
environment:
HTPASSWD: 'foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.'
docker --version
Docker version 17.09.0-ce, build afdb6d4
docker stack deploy -c docker-compose.yml auth
Ignoring unsupported options: links
Why is links not supported?
The official documentation does list what is not supported for compose and stack, and that includes links.
Links are not required to enable services to communicate - by default, any service can reach any other service at that service’s name. (See also, the Links topic in Networking in Compose.)
Hence that option is ignored when deploying a stack in swarm mode with a (version 3) Compose file.
$ docker stack deploy --compose-file docker-compose.yml vossibility
Ignoring unsupported options: links
So: why the option is not supported?
Because links are not needed in a compose scenario, since all services can already communicate one with another (being in the same network set up by compose).
You don't need links starting with version 2 of Compose files. Before v2, you needed to be explicit on what talked to what. In v2+, all containers on the same overlay or custom bridge network will be able to access all listening ports of other containers via their service name as DNS hostname.

Resources