# Simple Bash Script to Rebuild and Switch Discourse Containers

**URL:** <https://community.unix.com/t/simple-bash-script-to-rebuild-and-switch-discourse-containers/379418>\
**Category:** Discourse System Administration\
**Created:** [July 31, 2020, 4:59am UTC](https://community.unix.com/t/simple-bash-script-to-rebuild-and-switch-discourse-containers/379418 "2020-07-31T04:59:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [July 31, 2020, 4:59am UTC](https://community.unix.com/t/simple-bash-script-to-rebuild-and-switch-discourse-containers/379418/1 "2020-07-31T04:59:39Z")

</div>

Sometimes simple scripts are the best scripts.

Here is a simple script I use to:

1. Rebuild a "standing by" Discourse Docker container.
2. Wait 60 seconds and display countdown timer while new container "spins up".
3. Edit the apache2 configuration file in order to switch to the new container.
4. Switch containers by restarting apache2.
5. Display running docker containers after switching.

```plaintext
# cat /usr/local/bin/buildsocket

#!/bin/bash
/var/discourse/launcher rebuild socket-only
FROMHERE=60
echo -n "Countdown to container switch: "

for ((i=FROMHERE; i>=1; i--))
do
    echo -n $i" "
    sleep 1
done

sed -i.bak2 's/socket-only2\//socket-only\//' /etc/apache2/sites-available/community-le-ssl.conf 
service apache2 restart
watch docker ps

```

This is how I rebuild Discourse Docker containers.

I have two of these simple scripts as opposed to reading the container details from the command line, so I don't accidentally fat finger something in a single, more generic, script:

> /usr/local/bin/buildsocket

This script rebuilds the `socket-only` container and replaces `socket-only2`.

> /usr/local/bin/buildsocket2

This script rebuilds the `socket-only2` container and replaces `socket-only`.

Most everyone loves screenshots:

 ![Screen Shot 2020-07-31 at 11.49.53 AM](https://community.unix.com/uploads/default/original/2X/0/0f20b7b1444a50b88319431cefe109093578d13d.jpeg)

When the switch is complete (from restarting Apache2) `watch docker ps` is displayed, so we can see what is going on in the "container space".

This is a simple script which I use often these days.
