Skip to content

Commit 4b34076

Browse files
committed
Update docker
1 parent eae2d66 commit 4b34076

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

docker.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,13 @@ volumes:
408408
name: nest-prisma-docker-db
409409
```
410410

411-
After create docker-compose file, run this command: `docker compose up -d`
411+
After create docker-compose file, run this command: `docker compose up -d`. This command Starts your services in detached mode (running in the background) and build the images if they don't exist. Otherwise, it uses existing images
412412

413-
**Wait for db run first**:
413+
You can also use `docker compose up -d --build` to forces a rebuild of the images regardless of whether an image already exists. It ensures that any changes in your Dockerfile or build context are incorporated into the new image.
414+
415+
Using --build is particularly useful when you've updated your code or Dockerfile and want to make sure your containers are running the latest version.
416+
417+
### Wait for db run first
414418

415419
App can run already while db needs time to set up => we need to wait for db run first before running app
416420

@@ -434,6 +438,35 @@ mysql:
434438
retries: 20
435439
```
436440
441+
## ENTRYPOINT
442+
443+
The purpose of
444+
445+
```Dockerfile
446+
ENTRYPOINT ["./entrypoint.sh"]
447+
```
448+
449+
is to set entrypoint.sh as the entry point for the container. This means when the container starts, it will always execute `entrypoint.sh` first before running any command specified in CMD or provided at runtime.
450+
451+
Why Use ENTRYPOINT?
452+
453+
1. Ensures a Script Runs Before Anything Else
454+
- `entrypoint.sh` can be used to prepare the environment before the main process starts, such as:
455+
- Replacing environment variables in configuration files
456+
- Running database migrations
457+
- Checking for required services (e.g., waiting for a database to be ready)
458+
2. Allows Custom Commands While Keeping the Default Behavior
459+
If you define:
460+
461+
```
462+
ENTRYPOINT ["./entrypoint.sh"]
463+
CMD ["nginx", "-g", "daemon off;"]
464+
```
465+
466+
- The container will always execute entrypoint.sh first.
467+
- After entrypoint.sh finishes, it will run nginx -g 'daemon off;' (from CMD).
468+
- You can override CMD at runtime, but ENTRYPOINT will still execute first.
469+
437470
## Optimize docker image size
438471

439472
<https://github.com/webuild-community/advent-of-frontend/blob/main/2022/day-23.md>

micro-frontend.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ new ModuleFederationPlugin({
142142
new ModuleFederationPlugin({
143143
name: 'host',
144144
remotes: {
145-
remoteAppContainer: 'remoteApp@http://localhost:3001/remoteEntry.js', // remoateAppContainer is like the alias of the remote container
145+
// remoteAppContainer is like the alias of the remote container.
146+
// remoteApp is the 'name' the remote container
147+
// Basically, in the host app, when it read the remoteEntry.js file, there will be a global variable named `remoteApp`
148+
// You can read this line as: Go to fetch remoteApp's remoteEntry file and name it as remoteAppContainer
149+
remoteAppContainer: 'remoteApp@http://localhost:3001/remoteEntry.js',
146150
},
147151
shared: {
148152
react: { singleton: true, requiredVersion: '^18.0.0' },
@@ -154,7 +158,7 @@ new ModuleFederationPlugin({
154158
- singleton: true → Ensures only one instance of React is used across all apps.
155159
- requiredVersion → Ensures a compatible version is used.
156160

157-
Then inside host app, we import the module like this: `import remoteAppContainer/Button`
161+
Then inside host app, we import the module like this: `import remoteAppContainer/Button`. You can think of other remote container as a package and `remoteAppContainer` is the name of the package. Inside remote container, there are lots of exported modules. In this example, the module is `Button`.
158162

159163
#### Dynamic loading
160164

0 commit comments

Comments
 (0)