How to Update a Docker Container Without Losing Your Network Settings and Configs

A common frustration for Docker users—especially when managing tools like open-webui—is updating an image only to realize afterwards that your custom network settings, ports, or configuration files have vanished.

Since Docker containers are “immutable” (they cannot be edited in place), “updating” actually means deleting the old container and creating a new one based on the new image. If you do this blindly, you lose your data links and network connections.

This guide will walk you through how to upgrade safely while preserving everything.

Part 1: The Mystery of the Missing Network

Have you ever run docker rm and then docker run, only to find your container lost its connection to a custom network (like ai-network) and went back to the default bridge network?

The good news is that Docker Networks persist independently. Even if you delete all containers, the network still exists on your system unless you explicitly deleted it. The issue is that new containers need to be told which network to use.

1. Find your old networks

To see what networks are currently available on your system:

docker network ls

2. Check where your container lives

If you don’t remember which network a specific container is connected to, or want to see its internal IP address, use inspect:

Get Network Name:

docker inspect -f '{{range $key, $value := .NetworkSettings.Networks}}{{$key}}, {{end}}' <container_name_or_id>

Get Network Details (IP/ID):

docker inspect <container_name_or_id> | grep -A 15 "Networks"

Part 2: Two Ways to Fix It

Option A: The Hotfix (Connect without deleting)

If you just want a running container to join your custom network without deleting it (perhaps because you are in a rush or the update fails), use this command. This gives the container dual connectivity (it stays on bridge but also joins ai-network).

docker network connect ai-network <container_name>

To properly upgrade the software version and ensure a clean environment, you must “recreate” the container. Follow these steps carefully to keep your settings intact.


Part 3: Step-by-Step Safe Update Guide

Let’s assume you are updating open-webui while keeping your ai-network.

Step 1: Pull the New Image

First, download the latest version. The old container continues running normally during this step.

docker pull open-webui/open-webui:cuda

Step 2: Backup Your Configuration (Crucial!)

Before you touch anything, write down your Volumes, Ports, and Environment Variables.

Inspect your current container to see what it is currently running with:

# Check Mounts (Volumes) - vital for keeping data!
docker inspect <old_container_name> | grep -A 20 "Mounts"

# Check Environment Vars
docker inspect --format='{{range .Config.Env}}{{println .}}{{end}}' <old_container_name>

Write down anything starting with -e (Env vars) and -v (Volumes).

Step 3: Stop and Delete the Old Container

Now that you have your data safe in notes, you can clear the old container.

docker stop <old_container_name>
docker rm <old_container_name>

Step 4: Create the New Container with Old Settings

Now, spin up the new container. The most important flag here is --network, which restores your network connection.

docker run -d \
  --name open-webui \
  --network ai-network \       # <--- Vital: Restore your custom network
  -p 3000:8080 \              # <--- Restore port mapping
  -v /root/my_data:/app/data \ # <--- Restore data persistence
  -e OPENAI_API_KEY=sk-... \   # <--- Restore your secrets/env vars
  open-webui/open-webui:cuda

Appendix: Docker Network Cheat Sheet

Here is a quick reference guide for managing networks in the future:

GoalCommand
List all available networksdocker network ls
Find IP & Network of a containerdocker inspect -f '{{range $key, $value := .NetworkSettings.Networks}}{{$key}}: {{$value.IPAddress}}{{"\n"}}{{end}}' <name>
Connect a running container to a networkdocker network connect <network_name> <container_name>
Disconnect a container from bridgedocker network disconnect bridge <container_name>
Remove a specific networkdocker network rm <network_name>

Summary

The key to updating Docker containers is realizing that Networks and Volumes are saved objects, not part of the container itself. As long as you pass --network and -v when you run the new container, your data and connections will be perfectly preserved.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.