sounds simple, but I haven't found an easy way - I have docker containers written by me on a NAS - for 3rd party ones I just use watchtower, but for my own I just want to "upgrade" the container each time I change the docker file.
ie - I want to create a new container with the same name and all the same settings
I tried writing this upgrade.sh - but it doesn't work at all. Can anyone tell me how to fix this shell script?
#!/bin/bash
# Get container settings
settings=$(docker inspect --format='{{json .Config}}' $1)
# Stop container
docker stop $1
# Delete old container if it exists
if [ "$(docker ps -aqf name=$1_old)" ]; then
docker rm $1_old
fi
# Rename old container
docker rename $1 $1_old
# Create new container with extracted settings
docker create --name $1 --restart always $settings
# Start new container
docker start $1
in most cases I've created or updated the settings using the docker gui - so saying "just write a script that has the settings in it" is not a solution. I want to read the settings - ie port, volume and environment mappings and apply them to the new container.