Start command for an existing container

era/scripts/gen_container_cmd.sh recovers from a running (or stopped) container the docker run command by which it can be started again.

bash era/scripts/gen_container_cmd.sh
bash gen_container_cmd_ssh.sh --host=192.168.0.10 --user=user

Why this is needed

  • Updating the platform by recreating the container. The new image is loaded to the server manually, the startup string of the current container is retrieved with the command — and the new container starts from the new image with the same parameters as the old one: the same volumes, ports, variables, network. The step-by-step procedure is Cold upgrade of the docker container from a new image.

  • The container was started long ago, the launch parameters are forgotten, and it must be moved to another server.

  • One parameter must be changed — port, volume, variable — without reinstalling the whole installation.

  • The actual configuration must be recorded: what is running now, not what was intended.

The command only reads: it calls docker inspect and changes nothing.

How to use

Without arguments a container list is printed, from which you must select:

bash era/scripts/gen_container_cmd.sh

In the list row, besides the name, the container data directory is shown — the common directory of paths mounted into it:

Which container?
   1) directory: /opt/era<postfix>, container: era<postfix>
   2) directory: /opt/era<postfix>/postgresql, container: postgres<postfix>

Instances cannot be distinguished by name alone, but the directory answers the question immediately. If there is no common directory — the container has only named docker volumes — only the name remains in the row.

The name can be set directly — with a key or a positional argument:

bash era/scripts/gen_container_cmd.sh --container=era_11
bash era/scripts/gen_container_cmd.sh era_11

The result is printed to the screen and saved next to the log in the file <name>.run.sh.

docker run --name=era_11 \
           --volume=/opt/era_11/lib:/var/lib/era:rslave \
           --network=host \
           --restart=unless-stopped \
           --env=STARTTYPE=servinit \
           --cap-add=NET_ADMIN \
           --detach=true \
           era:1.11.0

What to know about the result

The command is recovered from the actual container state, therefore:

  • it contains all environment variables, including those substituted by the image itself;

  • passwords that got into environment variables at launch appear in the output in clear text — the .run.sh file is created with 0600 permissions, but it is better not to copy it from the screen into a shared chat;

  • volumes are listed as docker sees them: host paths, not what you entered during installation.

To restore the whole installation rather than one container, use the answers file — see era_installer/unattended.adoc#era-installer-unattended.

Permissions

docker inspect works without sudo if the user is in the docker group. If not, access is checked before any docker work, and in interactive mode the installer asks for a password, explaining why:

Docker needs root: the container list is read via sudo. Enter the password.

The check runs both before selecting a container from the list and before docker inspect by the name from --container: without it, missing permissions would look like missing containers.

In non-interactive mode, where sudo has nowhere to ask for a password, work stops with code 3 and one of three messages: docker is not installed, the daemon is not responding, or the daemon responds only to root — then root, membership in the docker group, or passwordless sudo is required.