• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


30 Nov, 2024

Updated at 14 Dec, 2024

Automatically adjust routing table at container startup

On a debian host I create an SSH container with the following docker file :

FROM debian:latest

RUN apt-get update && \
        apt-get install --yes openssh-server

# Expose the SSH port
EXPOSE 22/tcp

# Start SSH server on container startup
CMD ["/usr/sbin/sshd", "-D", "-p 22"]

While still keeping the “exec” form of the service launch (Docker Best Practices: Choosing Between RUN, CMD, and ENTRYPOINT | Docker) is there a way to add the following additional IP route ? :

192.168.40.0/24 via 192.168.30.4 dev eth0

Currently I’m doing this by manually launch the command :

sudo ip route add 192.168.40.0/24 via 192.168.30.4

I would prefer though if this additional route would be create automatically at each restart

My docker info :

Client: Docker Engine - Community
 Version:    27.3.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.17.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 4
  Running: 4
  Paused: 0
  Stopped: 0
 Images: 6
 Server Version: 27.3.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7f7fdf5fed64eb6a7caf99b3e12efcf9d60e311c
 runc version: v1.1.14-0-g2c9f560
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.0-26-amd64
 Operating System: Debian GNU/Linux 12 (bookworm)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.647GiB
 Name: testhost
 ID: e6ca5bef-53d1-495d-b5c9-f1102b5c10fc
 Docker Root Dir: /vmds/dockerdata
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Default Address Pools:
   Base: 192.168.30.0/24, Size: 26

3 posts - 2 participants

Read full topic