docker bind address already in use

Perhaps you’ve been playing with docker-compose, and you run into this error

docker bind address already in use

In my case I was editing my docker compose file, and removed a service before I ran docker-compose down. This meant the service was still running as docker-compose down did not bring down that specific service. In turn the port remained in use.

Solution

docker-compose down --remove-orphans

ZOMG, suddenly I remembered I indeed started those services, I iz dumbass.

Simple http API backend for testing purpose using docker/kubernetes

At work we are responsible for an API Gateway offering. Testing of that API gateway is often done by using an API backend. This post shows how to create a static API backend to which you can easily add responses.

While looking for solutions I did not want to maintain another image, so I tried using an existing image and add config to mold it into something we can use.

I’m going to show both docker-compose and kubernetes yaml, as I’ve used both for testing.

Note: Create a local directory html for static files. These files contain the ‘responses’ for the backend.

Big thanks to my colleague Mahesh, who showed me a lot of cool tricks with K8s and OpenShift! Not only that, he helps me a lot with my simple questions and it’s been a lot of fun to figure out our (work related) challenges!
If you’d like then take a look at his blog over here: Mahesh Chinthaka – Medium

Setup

First up is the docker compose file which we can use for testing our backend locally. This file was the basis forwhat I converted to the k8s yamls.

Docker compose

version: '3.8'

services:
  nginxbackend:
    image: nginxinc/nginx-unprivileged
    container_name: nginxapibackend

    ports:
      - "8080:8080/tcp"
    volumes:
      - ./html:/usr/share/nginx/html
    restart: unless-stopped

Run docker compose up -d to start the nginx backend.

You can test the backend by opening this endpoint in your browser:

http://localhost:8080/yourfile.json

Note that yourfile.json should be present in the html directory

Kubernetes

Note: I’m not going to expose the NGINX backend outside of our namespace as I only want it accessible from the API Gateway, which resides in the same namespace.

If you want to test the backend, use docker or change the service to your liking.

The setup changes slightly because I don’t want to use local storage in my kubernetes cluster. In this setup I am using configmaps for the static response files.

K8s step 1: Create the configmap

kubectl create configmap nginxhtml --from-file=./html/

In the next steps we’ll mount the configmap for use in the pod.

K8s step 2: Create the deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginxapibackend
  name: nginxapibackend
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxapibackend
  strategy: {}
  template:
    metadata:
      labels:
        app: nginxapibackend
    spec:
      containers:
      - image: nginxinc/nginx-unprivileged
        name: nginx
        volumeMounts:
          - name: nginxhtml
            mountPath: /usr/share/nginx/html
        ports:
          - containerPort: 8080
      volumes:
        - name: nginxhtml
          configMap:
            name: nginxhtml

Create the service

apiVersion: v1
kind: Service
metadata:
  name: nginxapibackend-service
  namespace: apim-dev
spec:
  selector:
    app: nginxapibackend
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080

Extra; Update the HTML configmap in kubernetes

You cannot update a configmap, so delete the current one and create a new one. Then recreate your pod so it uses the updated html directory.

kubectl delete configmap nginxhtml
kubectl create configmap nginxhtml --from-file=./html/
kubectl delete pod nginxapibackend-abcdefghij-abcde

Error relocating: Symbol not found

I was running a container from linuxserver.io, which is based on Alpine linux.

While this container ran fine for a while, it seems after a while I’m getting the following errors in the log:

transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_cipher_list: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_default_passwd_cb_userdata: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_free: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_use_certificate: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_sess_set_new_cb: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_current_cipher: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_privatekey: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_add_client_CA: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_ciphersuites: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_default_passwd_cb: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_write: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_use_certificate_file: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get0_alpn_selected: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_set_fd: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_shutdown: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_ctrl: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CIPHER_get_name: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_new: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_read: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_load_verify_locations: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_use_PrivateKey: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_get_cert_store: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_set_session: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_post_handshake_auth: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_use_certificate_chain_file: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_options: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_alert_desc_string_long: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_connect: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_keylog_callback: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_next_proto_select_cb: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: BIO_f_ssl: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_use_PrivateKey_file: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_free: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_peer_cert_chain: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_check_private_key: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_peer_certificate: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_verify_result: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: OPENSSL_init_ssl: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_shutdown: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_set_bio: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_pending: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_alpn_protos: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_certificate: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_msg_callback: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_ctrl: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_srp_password: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_new: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_set_connect_state: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_ex_data: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_error: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_get_version: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_set_ex_data: symbol not found
transmission  | Error relocating /usr/lib/libcurl.so.4: SSL_CTX_set_verify: symbol not found
transmission  | Error relocating /usr/bin/transmission-daemon: SSL_CTX_get_cert_store: symbol not found

It seems this is because there are incompatibilities between the minimal (musl) system C library (libc.so) that ships with Alpine Linux and the bigger (GNU) libc that ships with more typical Linux distributions. Those error messages hint that you’re tripping over something like that. (text copied from the post linked below)

More information in this thread: Error relocating – symbol not found – building docker-fpm-alpine image – Stack Overflow

In my case I was indeed running Ubuntu Linux as host for the Docker images.

I’ll update this post when I found the exact solution. For now I’m using another image provider for this specific goal.