Skip to content

Add Docker environment checks in various API server client scripts#3

Open
jogarcia-whoi wants to merge 1 commit into
mainfrom
docker-environment-check
Open

Add Docker environment checks in various API server client scripts#3
jogarcia-whoi wants to merge 1 commit into
mainfrom
docker-environment-check

Conversation

@jogarcia-whoi
Copy link
Copy Markdown
Contributor

Hi, everyone. I found some ways for a script to check if it's running inside a Docker container. I've implemented one of the methods in admin-tools/misc/getCruiseId.py. If you're satisfied with that approach, I'll apply it to a couple of other scripts that have the same need (admin-tools/misc/getLoweringId.py and admin-tools/sealog_postdive.sh).

@rgov
Copy link
Copy Markdown
Member

rgov commented Apr 14, 2023

Seems like a partial fix.

  1. The .dockerenv file isn't guaranteed to exist, is it? Do we have to modify the containers to add it?

  2. It's not just https:// vs http://. Outside the containers we need to connect to http://localhost/ or https://localhost/ according to the nginx configuration on the system (the AIS requires https, not all systems do).

    Inside a container it matters which container we are using. If it is the one hosting the server app, then we can use localhost as the hostname. Otherwise we would have to use a different hostname to route the request to the right container.

@jogarcia-whoi
Copy link
Copy Markdown
Contributor Author

jogarcia-whoi commented Apr 16, 2023

Seems like a partial fix.

1. The `.dockerenv` file isn't guaranteed to exist, is it? Do we have to modify the containers to add it?

2. It's not just https:// vs http://. Outside the containers we need to connect to `http://localhost/` or `https://localhost/` according to the nginx configuration on the system (the AIS requires https, not all systems do).
   Inside a container it matters _which_ container we are using. If it is the one hosting the server app, then we can use `localhost` as the hostname. Otherwise we would have to use a different hostname to route the request to the right container.

To answer point 1): I haven't found any documentation stating that /.dockerenv is guaranteed to exist but I've seen it in every single container I've opened a Bash session in. Additionally, it appears in several places in the moby source code. Docker/moby adds the file; we aren't creating, copying, or manipulating it. One thought I just had is that on the host machine docker will definitely be installed whereas docker probably won't be installed in the containers themselves-- maybe this is a better check?
To answer point 2): Roger that; If we're at the point where the script knows it's running inside a container then it could check for the existence of the server app and act accordingly. If the app exists on a local path, then a localhost URL would work. If the app doesn't exist locally, I'd have to figure out some way of having the container find the IP address of the Sealog server container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants