mirror of
https://github.com/jbranchaud/til
synced 2026-01-20 15:38:02 +00:00
Compare commits
3 Commits
ec766c9f2d
...
5db3686836
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5db3686836 | ||
|
|
fe9b62a631 | ||
|
|
15337dfd71 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1589 TILs and counting..._
|
_1590 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||||
@@ -216,6 +216,7 @@ See some of the other learning resources I work on:
|
|||||||
|
|
||||||
- [Configure Different Host And Container Ports](docker/configure-different-host-and-container-ports.md)
|
- [Configure Different Host And Container Ports](docker/configure-different-host-and-container-ports.md)
|
||||||
- [List Running Docker Containers](docker/list-running-docker-containers.md)
|
- [List Running Docker Containers](docker/list-running-docker-containers.md)
|
||||||
|
- [Prevent Containers From Running On Startup](docker/prevent-containers-from-running-on-startup.md)
|
||||||
- [Run A Basic PostgreSQL Server In Docker](docker/run-a-basic-postgresql-server-in-docker.md)
|
- [Run A Basic PostgreSQL Server In Docker](docker/run-a-basic-postgresql-server-in-docker.md)
|
||||||
|
|
||||||
### Drizzle
|
### Drizzle
|
||||||
|
|||||||
53
docker/prevent-containers-from-running-on-startup.md
Normal file
53
docker/prevent-containers-from-running-on-startup.md
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Prevent Containers From Running On Startup
|
||||||
|
|
||||||
|
I have a bunch of docker containers managed by Docker Desktop. Some are related
|
||||||
|
to projects I'm actively working on. Whereas many others are inactive projects.
|
||||||
|
|
||||||
|
When I restart my machine, regardless of which containers I had running or
|
||||||
|
turned off, several of them are booted into a running state on startup. This is
|
||||||
|
becaue their restart policy is set to `always`. That's fine for the project I'm
|
||||||
|
actively working on, but the others I would like to be _off_ by default.
|
||||||
|
|
||||||
|
I need to update each of their restart policies from `always` to `no`.
|
||||||
|
|
||||||
|
First, I need to figure out their container IDs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker ps --all
|
||||||
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||||
|
eb7b40aeba2d postgres:latest "docker-entrypoint.s…" 3 months ago Up 11 minutes 0.0.0.0:9875->5432/tcp still-postgres-1
|
||||||
|
eb9ab2213f2b postgres:latest "docker-entrypoint.s…" 3 months ago Exited (0) 11 minutes ago next-drizzle-migration-repro-app-postgres-1
|
||||||
|
ba792e185734 postgres:latest "docker-entrypoint.s…" 4 months ago Up 11 minutes 0.0.0.0:9876->5432/tcp better_reads-postgres-1
|
||||||
|
3139f9beae76 postgres:latest "docker-entrypoint.s…" 9 months ago Exited (128) 7 months ago basic-next-prisma-postgres-1
|
||||||
|
```
|
||||||
|
|
||||||
|
Referencing the `CONTAINER ID` and `NAMES` columns, I'm able to then inspect
|
||||||
|
each container and see the current `RestartPolicy`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker inspect eb9ab2213f2b | grep -A3 RestartPolicy
|
||||||
|
"RestartPolicy": {
|
||||||
|
"Name": "always",
|
||||||
|
"MaximumRetryCount": 0
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
I can then update the `RestartPolicy` to be `no`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker update --restart no eb9ab2213f2b
|
||||||
|
```
|
||||||
|
|
||||||
|
Inpsecting that container again, I can see the updated policy:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker inspect eb9ab2213f2b | grep -A3 RestartPolicy
|
||||||
|
"RestartPolicy": {
|
||||||
|
"Name": "no",
|
||||||
|
"MaximumRetryCount": 0
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
Rinse and repeat for each of the offending containers.
|
||||||
|
|
||||||
|
[source](https://stackoverflow.com/questions/45423334/stopping-docker-containers-from-being-there-on-startup)
|
||||||
@@ -23,11 +23,11 @@ version from my `.tool-versions` file with a step that uses `set-output`.
|
|||||||
- name: Read Node.js version to install from `.tool-versions`
|
- name: Read Node.js version to install from `.tool-versions`
|
||||||
id: nodejs
|
id: nodejs
|
||||||
run: >-
|
run: >-
|
||||||
echo "::set-output name=NODE_VERSION::$(
|
echo "NODE_VERSION=$(
|
||||||
cat .tool-versions |
|
cat .tool-versions |
|
||||||
grep nodejs |
|
grep nodejs |
|
||||||
sed 's/nodejs \(.*\)$/\1/'
|
sed 's/nodejs \(.*\)$/\1/'
|
||||||
)"
|
)" >> $GITHUB_OUTPUT
|
||||||
```
|
```
|
||||||
|
|
||||||
`echo` runs the command in the string which sets `NODE_VERSION` as an output
|
`echo` runs the command in the string which sets `NODE_VERSION` as an output
|
||||||
@@ -45,4 +45,4 @@ This output value can be referenced in a later step.
|
|||||||
`steps` has a reference to the `nodejs` step (note the `id` above) which then
|
`steps` has a reference to the `nodejs` step (note the `id` above) which then
|
||||||
has `outputs` like the `NODE_VERSION`.
|
has `outputs` like the `NODE_VERSION`.
|
||||||
|
|
||||||
[source](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions)
|
[source](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter)
|
||||||
|
|||||||
Reference in New Issue
Block a user